diff --git a/jac/jaclang/compiler/absyntree.py b/jac/jaclang/compiler/absyntree.py index f5a85d890..97cce9ba3 100644 --- a/jac/jaclang/compiler/absyntree.py +++ b/jac/jaclang/compiler/absyntree.py @@ -348,7 +348,28 @@ class Expr(AstNode): def __init__(self) -> None: """Initialize expression node.""" - self.expr_type = "" + self._sym_type: str = "NoType" + self._type_sym_tab: Optional[SymbolTable] = None + + @property + def sym_type(self) -> str: + """Get symbol type.""" + return self._sym_type + + @sym_type.setter + def sym_type(self, sym_type: str) -> None: + """Set symbol type.""" + self._sym_type = sym_type + + @property + def type_sym_tab(self) -> Optional[SymbolTable]: + """Get type symbol table.""" + return self._type_sym_tab + + @type_sym_tab.setter + def type_sym_tab(self, type_sym_tab: SymbolTable) -> None: + """Set type symbol table.""" + self._type_sym_tab = type_sym_tab class AtomExpr(Expr, AstSymbolStubNode): @@ -439,8 +460,6 @@ def __init__(self) -> None: self._sym_name: str = "" self._sym_category: SymbolType = SymbolType.UNKNOWN self._py_ctx_func: Type[ast3.AST] = ast3.Load - self._sym_type: str = "NoType" - self._type_sym_tab: Optional[SymbolTable] = None AtomExpr.__init__(self) @property @@ -479,26 +498,6 @@ def py_ctx_func(self, py_ctx_func: Type[ast3.AST]) -> None: """Set python context function.""" self._py_ctx_func = py_ctx_func - @property - def sym_type(self) -> str: - """Get symbol type.""" - return self._sym_type - - @sym_type.setter - def sym_type(self, sym_type: str) -> None: - """Set symbol type.""" - self._sym_type = sym_type - - @property - def type_sym_tab(self) -> Optional[SymbolTable]: - """Get type symbol table.""" - return self._type_sym_tab - - @type_sym_tab.setter - def type_sym_tab(self, type_sym_tab: SymbolTable) -> None: - """Set type symbol table.""" - self._type_sym_tab = type_sym_tab - @property def sem_token(self) -> Optional[tuple[SemTokType, SemTokMod]]: """Resolve semantic token.""" diff --git a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index 5b4e2e2e0..4b200e442 100644 --- a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -35,8 +35,6 @@ def enter_node(self, node: ast.AstNode) -> None: if hasattr(self, f"enter_{pascal_to_snake(type(node).__name__)}"): getattr(self, f"enter_{pascal_to_snake(type(node).__name__)}")(node) - # TODO: Make (AstSymbolNode::name_spec.sym_typ and Expr::expr_type) the same - # TODO: Introduce AstTypedNode to be a common parent for Expr and AstSymbolNode if isinstance(node, ast.Expr): self.enter_expr(node) @@ -257,7 +255,7 @@ def enter_expr(self: FuseTypeInfoPass, node: ast.Expr) -> None: mypy_node = node.gen.mypy_ast[0] if mypy_node in self.node_type_hash: mytype: MyType = self.node_type_hash[mypy_node] - node.expr_type = self.__call_type_handler(mytype) or "" + node.sym_type = self.__call_type_handler(mytype) or "" # Set they symbol type for collection expression. # diff --git a/jac/jaclang/compiler/passes/main/tests/test_type_check_pass.py b/jac/jaclang/compiler/passes/main/tests/test_type_check_pass.py index 80d4b13e7..78ca9e978 100644 --- a/jac/jaclang/compiler/passes/main/tests/test_type_check_pass.py +++ b/jac/jaclang/compiler/passes/main/tests/test_type_check_pass.py @@ -59,6 +59,6 @@ def test_type_coverage(self) -> None: self.assertIn("HasVar - species - Type: builtins.str", out) self.assertIn("myDog - Type: type_info.Dog", out) self.assertIn("Body - Type: type_info.Dog.Body", out) - self.assertEqual(out.count("Type: builtins.str"), 39) + self.assertEqual(out.count("Type: builtins.str"), 29) for i in lis: self.assertNotIn(i, out) diff --git a/jac/jaclang/utils/treeprinter.py b/jac/jaclang/utils/treeprinter.py index a896e78d8..6b2b118ca 100644 --- a/jac/jaclang/utils/treeprinter.py +++ b/jac/jaclang/utils/treeprinter.py @@ -144,7 +144,7 @@ def __node_repr_in_tree(node: AstNode) -> str: out += f" SymbolPath: {symbol}" return out elif isinstance(node, ast.Expr): - return f"{node.__class__.__name__} - Type: {node.expr_type}" + return f"{node.__class__.__name__} - Type: {node.sym_type}" else: return f"{node.__class__.__name__}, {access}"