Skip to content

Commit

Permalink
failed test case fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Sep 15, 2024
1 parent 373a016 commit 8db06cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
22 changes: 13 additions & 9 deletions jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
7 changes: 4 additions & 3 deletions jac/jaclang/langserve/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8db06cb

Please sign in to comment.