mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 18:29:00 +00:00
fix: type aliasing bug
This commit is contained in:
parent
0d8e574414
commit
5a386a7481
2 changed files with 27 additions and 7 deletions
|
@ -1344,7 +1344,7 @@ impl Context {
|
|||
return Ok(SubstituteResult::__Call__(instance));
|
||||
}
|
||||
}
|
||||
let hint = if other == &ClassType {
|
||||
let hint = if self.subtype_of(other, &ClassType) {
|
||||
Some(switch_lang! {
|
||||
"japanese" => format!("インスタンスを生成したい場合は、{}.newを使用してください", obj.to_string_notype()),
|
||||
"simplified_chinese" => format!("如果要生成实例,请使用 {}.new", obj.to_string_notype()),
|
||||
|
|
|
@ -55,8 +55,7 @@ impl ASTLowerer {
|
|||
} else {
|
||||
sig.inspect().cloned()
|
||||
};
|
||||
let block = hir::Block::new(vec![chunk]);
|
||||
let found_body_t = block.ref_t();
|
||||
let found_body_t = chunk.ref_t();
|
||||
let ast::VarPattern::Ident(ident) = &sig.pat else { unreachable!() };
|
||||
let id = body.id;
|
||||
if let Some(spec_t) = opt_spec_t {
|
||||
|
@ -71,13 +70,35 @@ impl ASTLowerer {
|
|||
.context
|
||||
.assign_var_sig(&sig, found_body_t, id, None)?;
|
||||
}
|
||||
// FIXME: Identifier::new should be used
|
||||
let mut ident = hir::Identifier::bare(ident.clone());
|
||||
ident.vi.t = found_body_t.clone();
|
||||
let t = match found_body_t {
|
||||
Type::ClassType => {
|
||||
let t = mono(format!("{}{}", self.module.context.path(), ident.raw));
|
||||
v_enum(set! { ValueObj::builtin_class(t) })
|
||||
}
|
||||
Type::TraitType => {
|
||||
let t = mono(format!("{}{}", self.module.context.path(), ident.raw));
|
||||
v_enum(set! { ValueObj::builtin_trait(t) })
|
||||
}
|
||||
_ => found_body_t.clone(),
|
||||
};
|
||||
// Typ = 'typ': ClassType
|
||||
// => 'typ': {<type Typ>}
|
||||
if let hir::Expr::TypeAsc(hir::TypeAscription { expr, .. }) = &chunk {
|
||||
if let hir::Expr::Accessor(acc) = expr.as_ref() {
|
||||
if let Some(name) = acc.local_name() {
|
||||
let name = VarName::from_str(Str::rc(name));
|
||||
if let Some(vi) = self.module.context.get_mut_current_scope_var(&name) {
|
||||
vi.t = t.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ident.vi.t = t;
|
||||
ident.vi.py_name = py_name;
|
||||
ident.vi.def_loc = self.module.context.absolutize(ident.raw.name.loc());
|
||||
let sig = hir::VarSignature::new(ident, sig.t_spec);
|
||||
let body = hir::DefBody::new(body.op, block, body.id);
|
||||
let body = hir::DefBody::new(body.op, hir::Block::new(vec![chunk]), body.id);
|
||||
Ok(hir::Def::new(hir::Signature::Var(sig), body))
|
||||
}
|
||||
|
||||
|
@ -526,7 +547,6 @@ impl ASTLowerer {
|
|||
t: &Type,
|
||||
py_name: Str,
|
||||
) -> LowerResult<()> {
|
||||
log!(err "{ident}(= {py_name}): {t}");
|
||||
// .X = 'x': Type
|
||||
if ident.is_raw() {
|
||||
return Ok(());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue