Skip to content

Commit

Permalink
fix: parameter type inferring bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jul 3, 2023
1 parent 60f82ba commit 614e48e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 2 additions & 6 deletions crates/erg_compiler/context/inquire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ impl Context {
) -> Triple<VarInfo, TyCheckError> {
// 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() {
Expand Down Expand Up @@ -894,7 +894,7 @@ impl Context {
) -> SingleTyCheckResult<VarInfo> {
// 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))))
Expand Down Expand Up @@ -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()))
Expand Down
8 changes: 8 additions & 0 deletions crates/erg_compiler/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Str> {
match self {
Expand Down

0 comments on commit 614e48e

Please sign in to comment.