diff --git a/crates/erg_compiler/context/inquire.rs b/crates/erg_compiler/context/inquire.rs index d33374720..d35f98d4a 100644 --- a/crates/erg_compiler/context/inquire.rs +++ b/crates/erg_compiler/context/inquire.rs @@ -552,7 +552,7 @@ impl Context { ) -> Triple { // get_attr_info(?T, aaa) == None // => ?T(<: Structural({ .aaa = ?U })) - if self.in_subr() && PYTHON_MODE { + if PYTHON_MODE && obj.var_info().is_some_and(|vi| vi.kind.is_parameter()) { let t = free_var(self.level, Constraint::new_type_of(Type)); if let Some(fv) = obj.ref_t().as_free() { if fv.get_sub().is_some() { @@ -894,7 +894,7 @@ impl Context { ) -> SingleTyCheckResult { // search_method_info(?T, aaa, pos_args: [1, 2]) == None // => ?T(<: Structural({ .aaa = (self: ?T, ?U, ?V) -> ?W })) - if PYTHON_MODE && self.in_subr() { + if PYTHON_MODE && obj.var_info().is_some_and(|vi| vi.kind.is_parameter()) { let nd_params = pos_args .iter() .map(|_| ParamTy::Pos(free_var(self.level, Constraint::new_type_of(Type)))) @@ -2559,10 +2559,6 @@ impl Context { } } - pub(crate) fn in_subr(&self) -> bool { - self.kind.is_subr() || self.get_outer().map_or(false, |ctx| ctx.in_subr()) - } - pub(crate) fn gen_type(&self, ident: &ast::Identifier) -> Type { let vis = ident.vis.display_as_accessor(); mono(format!("{}{vis}{}", self.name, ident.inspect())) diff --git a/crates/erg_compiler/hir.rs b/crates/erg_compiler/hir.rs index 2664cccb0..74704e0f1 100644 --- a/crates/erg_compiler/hir.rs +++ b/crates/erg_compiler/hir.rs @@ -2529,6 +2529,14 @@ impl Expr { } } + pub fn var_info(&self) -> Option<&VarInfo> { + match self { + Expr::Accessor(acc) => Some(acc.var_info()), + Expr::TypeAsc(t_asc) => t_asc.expr.var_info(), + _ => None, + } + } + /// 参照するオブジェクト自体が持っている名前(e.g. Int.qual_name == Some("int"), Socket!.qual_name == Some("io.Socket!")) pub fn qual_name(&self) -> Option { match self {