Struct erg_compiler::hir::NormalDict
source · pub struct NormalDict {
pub l_brace: Token,
pub r_brace: Token,
pub t: Type,
pub kvs: Vec<KeyValue>,
}
Fields§
§l_brace: Token
§r_brace: Token
§t: Type
§kvs: Vec<KeyValue>
Implementations§
source§impl NormalDict
impl NormalDict
sourcepub fn new(
l_brace: Token,
r_brace: Token,
kv_ts: HashMap<TyParam, TyParam>,
kvs: Vec<KeyValue>
) -> Self
pub fn new(
l_brace: Token,
r_brace: Token,
kv_ts: HashMap<TyParam, TyParam>,
kvs: Vec<KeyValue>
) -> Self
Examples found in repository?
lower.rs (lines 694-699)
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
fn lower_normal_dict(&mut self, dict: ast::NormalDict) -> LowerResult<hir::NormalDict> {
log!(info "enter {}({dict})", fn_name!());
let mut union = dict! {};
let mut new_kvs = vec![];
for kv in dict.kvs {
let loc = kv.loc();
let key = self.lower_expr(kv.key)?;
let value = self.lower_expr(kv.value)?;
if union.insert(key.t(), value.t()).is_some() {
return Err(LowerErrors::from(LowerError::syntax_error(
self.cfg.input.clone(),
line!() as usize,
loc,
String::from(&self.ctx.name[..]),
switch_lang!(
"japanese" => "Dictの値は全て同じ型である必要があります",
"simplified_chinese" => "Dict的值必须是同一类型",
"traditional_chinese" => "Dict的值必須是同一類型",
"english" => "Values of Dict must be the same type",
)
.to_owned(),
Some(
switch_lang!(
"japanese" => "Int or Strなど明示的に型を指定してください",
"simplified_chinese" => "明确指定类型,例如: Int or Str",
"traditional_chinese" => "明確指定類型,例如: Int or Str",
"english" => "please specify the type explicitly, e.g. Int or Str",
)
.to_owned(),
),
)));
}
new_kvs.push(hir::KeyValue::new(key, value));
}
for key_t in union.keys() {
let loc = Location::concat(&dict.l_brace, &dict.r_brace);
// check if key_t is Eq
if let Err(errs) = self.ctx.sub_unify(key_t, &mono("Eq"), loc, None) {
self.errs.extend(errs);
}
}
let kv_ts = if union.is_empty() {
dict! {
ty_tp(free_var(self.ctx.level, Constraint::new_type_of(Type::Type))) =>
ty_tp(free_var(self.ctx.level, Constraint::new_type_of(Type::Type)))
}
} else {
union
.into_iter()
.map(|(k, v)| (TyParam::t(k), TyParam::t(v)))
.collect()
};
// TODO: lint
/*
if is_duplicated {
self.warns.push(LowerWarning::syntax_error(
self.cfg.input.clone(),
line!() as usize,
normal_set.loc(),
String::arc(&self.ctx.name[..]),
switch_lang!(
"japanese" => "要素が重複しています",
"simplified_chinese" => "元素重复",
"traditional_chinese" => "元素重複",
"english" => "Elements are duplicated",
),
None,
));
}
Ok(normal_set)
*/
Ok(hir::NormalDict::new(
dict.l_brace,
dict.r_brace,
kv_ts,
new_kvs,
))
}
Trait Implementations§
source§impl Clone for NormalDict
impl Clone for NormalDict
source§fn clone(&self) -> NormalDict
fn clone(&self) -> NormalDict
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for NormalDict
impl Debug for NormalDict
source§impl Display for NormalDict
impl Display for NormalDict
source§impl HasType for NormalDict
impl HasType for NormalDict
fn ref_t(&self) -> &Type
fn ref_mut_t(&mut self) -> &mut Type
fn signature_t(&self) -> Option<&Type>
fn signature_mut_t(&mut self) -> Option<&mut Type>
fn t(&self) -> Type
fn inner_ts(&self) -> Vec<Type>
fn lhs_t(&self) -> &Type
fn rhs_t(&self) -> &Type
source§impl Hash for NormalDict
impl Hash for NormalDict
source§impl Locational for NormalDict
impl Locational for NormalDict
source§impl NestedDisplay for NormalDict
impl NestedDisplay for NormalDict
source§impl NoTypeDisplay for NormalDict
impl NoTypeDisplay for NormalDict
fn to_string_notype(&self) -> String
source§impl PartialEq<NormalDict> for NormalDict
impl PartialEq<NormalDict> for NormalDict
source§fn eq(&self, other: &NormalDict) -> bool
fn eq(&self, other: &NormalDict) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.