diff --git a/midas/checker/checker.py b/midas/checker/checker.py index ab7261c..3100587 100644 --- a/midas/checker/checker.py +++ b/midas/checker/checker.py @@ -19,6 +19,7 @@ from midas.checker.types import ( Type, UnitType, UnknownType, + unfold_type, ) from midas.lexer.midas import MidasLexer from midas.lexer.token import Token @@ -178,13 +179,6 @@ class Checker( stmts: list[m.Stmt] = parser.parse() self.ctx.resolve(stmts) - def unfold_type(self, type: Type) -> Type: - match type: - case AliasType(type=ref_type): - return self.unfold_type(ref_type) - case _: - return type - def is_subtype(self, type1: Type, type2: Type) -> bool: """Check whether `type1` is a subtype of `type2` @@ -470,7 +464,7 @@ class Checker( def _assign_attr(self, location: Location, target: p.GetExpr, value_type: Type): object: Type = self.type_of(target.object) - base_object: Type = self.unfold_type(object) + base_object: Type = unfold_type(object) match base_object: case ComplexType(properties=properties): if target.name not in properties: @@ -611,7 +605,7 @@ class Checker( def visit_get_expr(self, expr: p.GetExpr) -> Type: object: Type = self.type_of(expr.object) - base_object: Type = self.unfold_type(object) + base_object: Type = unfold_type(object) match base_object: case ComplexType(properties=properties): if expr.name not in properties: diff --git a/midas/checker/types.py b/midas/checker/types.py index 15079e0..ee41e14 100644 --- a/midas/checker/types.py +++ b/midas/checker/types.py @@ -120,6 +120,14 @@ def substitute_typevars(type: Type, substitutions: dict[str, Type]) -> Type: raise NotImplementedError(f"Unsupported type {type}") +def unfold_type(type: Type) -> Type: + match type: + case AliasType(type=ref_type): + return unfold_type(ref_type) + case _: + return type + + Type = ( BaseType | AliasType