diff --git a/compiler/erg_compiler/codegen.rs b/compiler/erg_compiler/codegen.rs index 96c67344..c136fa58 100644 --- a/compiler/erg_compiler/codegen.rs +++ b/compiler/erg_compiler/codegen.rs @@ -2376,14 +2376,15 @@ impl PyCodeGenerator { log!(info "entered {}", fn_name!()); let line = sig.ln_begin().unwrap(); let class_name = sig.ident().inspect(); - let ident = Identifier::public_with_line(DOT, Str::ever("__init__"), line); + let mut ident = Identifier::public_with_line(DOT, Str::ever("__init__"), line); + ident.vi.t = __new__.clone(); let param_name = fresh_varname(); let param = VarName::from_str_and_line(Str::from(param_name.clone()), line); let param = NonDefaultParamSignature::new(ParamPattern::VarName(param), None); let self_param = VarName::from_str_and_line(Str::ever("self"), line); let self_param = NonDefaultParamSignature::new(ParamPattern::VarName(self_param), None); let params = Params::new(vec![self_param, param], None, vec![], None); - let subr_sig = SubrSignature::new(ident, params, __new__.clone()); + let subr_sig = SubrSignature::new(ident, params); let mut attrs = vec![]; match __new__.non_default_params().unwrap()[0].typ() { // namedtupleは仕様上::xなどの名前を使えない @@ -2431,11 +2432,12 @@ impl PyCodeGenerator { log!(info "entered {}", fn_name!()); let class_ident = sig.ident(); let line = sig.ln_begin().unwrap(); - let ident = Identifier::public_with_line(DOT, Str::ever("new"), line); + let mut ident = Identifier::public_with_line(DOT, Str::ever("new"), line); + ident.vi.t = __new__; let param_name = fresh_varname(); let param = VarName::from_str_and_line(Str::from(param_name.clone()), line); let param = NonDefaultParamSignature::new(ParamPattern::VarName(param), None); - let sig = SubrSignature::new(ident, Params::new(vec![param], None, vec![], None), __new__); + let sig = SubrSignature::new(ident, Params::new(vec![param], None, vec![], None)); let arg = PosArg::new(Expr::Accessor(Accessor::private_with_line( Str::from(param_name), line, diff --git a/compiler/erg_compiler/context/tyvar.rs b/compiler/erg_compiler/context/tyvar.rs index a5d06b45..8ef99d69 100644 --- a/compiler/erg_compiler/context/tyvar.rs +++ b/compiler/erg_compiler/context/tyvar.rs @@ -686,8 +686,11 @@ impl Context { self.deref_tyvar(mem::take(var.ref_mut_t()), Covariant, var.loc())?; } hir::Signature::Subr(subr) => { - subr.t = - self.deref_tyvar(mem::take(&mut subr.t), Covariant, subr.loc())?; + *subr.ref_mut_t() = self.deref_tyvar( + mem::take(subr.ref_mut_t()), + Covariant, + subr.loc(), + )?; } } for chunk in attr.body.block.iter_mut() { @@ -738,8 +741,11 @@ impl Context { self.deref_tyvar(mem::take(var.ref_mut_t()), Covariant, var.loc())?; } hir::Signature::Subr(subr) => { - subr.t = - self.deref_tyvar(mem::take(&mut subr.t), Covariant, subr.loc())?; + *subr.ref_mut_t() = self.deref_tyvar( + mem::take(subr.ref_mut_t()), + Covariant, + subr.loc(), + )?; } } for chunk in def.body.block.iter_mut() { diff --git a/compiler/erg_compiler/hir.rs b/compiler/erg_compiler/hir.rs index a874101f..16575ffd 100644 --- a/compiler/erg_compiler/hir.rs +++ b/compiler/erg_compiler/hir.rs @@ -437,6 +437,11 @@ impl Identifier { self.name.inspect() } + /// show dot + name (no qual_name & type) + pub fn show(&self) -> String { + format!("{}{}", fmt_option!(self.dot), self.name) + } + pub fn is_procedural(&self) -> bool { self.name.is_procedural() } @@ -1366,22 +1371,45 @@ impl Params { pub struct SubrSignature { pub ident: Identifier, pub params: Params, - pub t: Type, } impl NestedDisplay for SubrSignature { fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { - write!(f, "{}{} (: {})", self.ident, self.params, self.t,) + write!( + f, + "{}{} (: {})", + self.ident.show(), + self.params, + self.ident.t() + ) } } impl_display_from_nested!(SubrSignature); impl_locational!(SubrSignature, ident, params); -impl_t!(SubrSignature); + +impl HasType for SubrSignature { + #[inline] + fn ref_t(&self) -> &Type { + self.ident.ref_t() + } + #[inline] + fn ref_mut_t(&mut self) -> &mut Type { + self.ident.ref_mut_t() + } + #[inline] + fn signature_t(&self) -> Option<&Type> { + self.ident.signature_t() + } + #[inline] + fn signature_mut_t(&mut self) -> Option<&mut Type> { + self.ident.signature_mut_t() + } +} impl SubrSignature { - pub const fn new(ident: Identifier, params: Params, t: Type) -> Self { - Self { ident, params, t } + pub const fn new(ident: Identifier, params: Params) -> Self { + Self { ident, params } } pub fn is_procedural(&self) -> bool { diff --git a/compiler/erg_compiler/lower.rs b/compiler/erg_compiler/lower.rs index 89fd1b98..b75efbf2 100644 --- a/compiler/erg_compiler/lower.rs +++ b/compiler/erg_compiler/lower.rs @@ -988,8 +988,9 @@ impl ASTLowerer { id, found_body_t, )?; - let ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name); - let sig = hir::SubrSignature::new(ident, params, t); + let mut ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name); + ident.vi.t = t; + let sig = hir::SubrSignature::new(ident, params); let body = hir::DefBody::new(body.op, block, body.id); Ok(hir::Def::new(hir::Signature::Subr(sig), body)) } @@ -1019,7 +1020,7 @@ impl ASTLowerer { ); let block = self.lower_block(body.block)?; let ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name); - let sig = hir::SubrSignature::new(ident, params, Type::Failure); + let sig = hir::SubrSignature::new(ident, params); let body = hir::DefBody::new(body.op, block, body.id); Ok(hir::Def::new(hir::Signature::Subr(sig), body)) } diff --git a/src/dummy.rs b/src/dummy.rs index 98ed99a9..a75f1da7 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -155,9 +155,7 @@ impl Runnable for DummyVM { .to_string(), ); if let Some(Expr::Def(def)) = last { - res.push_str(&format!(" ({}: ", def.sig.ident())); - res.push_str(&def.sig.t().to_string()); - res.push(')'); + res.push_str(&format!(" ({})", def.sig.ident())); } } Ok(res)