diff --git a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index ceb427c991..e96d7faead 100644 --- a/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -272,7 +272,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.sym_type = self.__call_type_handler(mytype) or "" + node.sym_type = self.__call_type_handler(mytype) or node.sym_type # Set they symbol type for collection expression. # @@ -474,9 +474,13 @@ def enter_builtin_type(self, node: ast.BuiltinType) -> None: def get_type_from_instance(self, mypy_type: MypyTypes.Instance) -> Optional[str]: """Get type info from mypy type Instance.""" - # NOTE: Returning str(mypy_type) won't work since for literal values it would be + # FIXME: Returning str(mypy_type) won't work for literal values since it would be # like Literal['foo'] instead of builtins.str, so we need to get the type fullname. - return mypy_type.type.fullname + # Not sure if this is the best way to do it. + ret = str(mypy_type) + if ret.startswith("Literal[") and ret.endswith("]"): + return mypy_type.type.fullname + return ret def get_type_from_callable_type( self, mypy_type: MypyTypes.CallableType @@ -587,7 +591,7 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: # right index slice is a range then it's type is the same as left if right.is_range: - right.name_spec.sym_type = left.sym_type + right.sym_type = left.sym_type continue # left type is a dictionary @@ -600,7 +604,7 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: else: continue - right.name_spec.sym_type = node_type + right.sym_type = node_type # Getting the correct symbol table and link it type_symtab: Optional[SymbolTable] = self.ir.sym_tab @@ -616,10 +620,10 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: type_symtab = type_symtab.find_scope(j) if type_symtab is None: break - right.name_spec.type_sym_tab = type_symtab + right.type_sym_tab = type_symtab else: if left.type_sym_tab: - right.name_spec.sym = left.type_sym_tab.lookup(right.sym_name) - if right.name_spec.sym: - right.name_spec.sym.add_use(right.name_spec) + right.sym = left.type_sym_tab.lookup(right.sym_name) + if right.sym: + right.sym.add_use(right.name_spec) diff --git a/jac/jaclang/langserve/utils.py b/jac/jaclang/langserve/utils.py index 5961819bc7..4b0085aec0 100644 --- a/jac/jaclang/langserve/utils.py +++ b/jac/jaclang/langserve/utils.py @@ -133,9 +133,10 @@ def find_index( ) -> Optional[int]: """Find index.""" index = None - for i, j in enumerate( - [get_token_start(i, sem_tokens) for i in range(0, len(sem_tokens), 5)] - ): + + # A list contains all the token start positions. + token_start_list = [get_token_start(i, sem_tokens) for i in range(0, len(sem_tokens), 5)] + for i, j in enumerate(token_start_list): if j[0] == line and j[1] <= char <= j[2]: return i