Skip to content

Commit

Permalink
Fixing an issue with dict accessing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtm98 committed Sep 11, 2024
1 parent 615f3a2 commit 0a9cfaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def __collect_type_from_symbol(self, node: ast.AstSymbolNode) -> None:
)

def __check_builltin_symbol(self, node: ast.NameAtom) -> None:
print(node.loc)
if isinstance(node.parent, ast.AtomTrailer) and node is node.parent.right:
return
builtins_sym_tab = self.ir.sym_tab.find_scope("builtins")
Expand Down Expand Up @@ -571,6 +570,10 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None:
type_symtab: Optional[SymbolTable] = self.ir.sym_tab
assert isinstance(self.ir, ast.Module)
assert isinstance(type_symtab, SymbolTable)

if re.match(r"builtins.(list|dict|tuple)", node_type):
node_type = re.sub(r"\[.*\]", "", node_type)

for j in node_type.split("."):
if j == self.ir.name:
continue
Expand Down
4 changes: 4 additions & 0 deletions jac/jaclang/tests/fixtures/builtins_test.jac
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ with entry {
str(6).count("6");
int("5");

b: dict[str, list[int]] = {"a": [2, 3, 4]};
b.keys();
b["a"].append(9);

dir(a);
}
6 changes: 5 additions & 1 deletion jac/jaclang/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ def test_builtins_loading(self) -> None:
)
self.assertRegex(
stdout_value,
r"11\:5 \- 11\:8.*Name - dir - .*SymbolPath: builtins_test.builtins.dir",
r"15\:5 \- 15\:8.*Name - dir - .*SymbolPath: builtins_test.builtins.dir",
)
self.assertRegex(
stdout_value,
r"13\:12 \- 13\:18.*Name - append - .*SymbolPath: builtins_test.builtins.list.append",
)

def test_ast_dotgen(self) -> None:
Expand Down

0 comments on commit 0a9cfaa

Please sign in to comment.