Skip to content

Commit

Permalink
register: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 27, 2023
1 parent 4185535 commit 6ac11b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
20 changes: 14 additions & 6 deletions rivetc/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def import_module(self, sf, decl):
if len(decl.subimports) > 0:
for subimport in decl.subimports:
self.import_module(sf, subimport)
subimport.id=id(subimport.mod_sym)
return
mod = self.load_module_files(
decl.path, decl.alias, sf.file, decl.pos
Expand Down Expand Up @@ -156,14 +157,21 @@ def import_graph(self):
deps.append("core")
for d in fp.decls:
if isinstance(d, ast.ImportDecl):
if not d.mod_sym:
continue # module not found
if d.mod_sym.name == fp.sym.name:
report.error("import cycle detected", d.pos)
continue
deps.append(d.mod_sym.name)
if len(d.subimports) > 0:
for subimport in d.subimports:
self.import_graph_mod(subimport, deps, fp)
else:
self.import_graph_mod(d, deps, fp)
g.add(fp.sym.name, deps)
return g

def import_graph_mod(self, d, deps, fp):
if not d.mod_sym:
return # module not found
if d.mod_sym.name == fp.sym.name:
report.error("import cycle detected", d.pos)
return
deps.append(d.mod_sym.name)

def load_root_module(self):
if path.isdir(self.prefs.input):
Expand Down
14 changes: 7 additions & 7 deletions rivetc/src/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,17 @@ def walk_decls(self, decls):
report.error(e.args[0], decl.name_pos)
self.abi = old_abi
self.sym = old_sym

def walk_import_decl(self, decl):
if len(decl.subimports) > 0:
for subimport in decl.subimports:
self.walk_import_decl(subimport)
elif decl.glob:
for symbol in decl.mod_sym.syms:
if not symbol.is_public:
continue
self.check_imported_symbol(symbol, decl.pos)
self.source_file.imported_symbols[symbol.name] = symbol
elif len(decl.import_list) == 0:
if decl.is_public:
try:
Expand All @@ -218,12 +224,6 @@ def walk_import_decl(self, decl):
else:
self.source_file.imported_symbols[decl.alias
] = decl.mod_sym
elif decl.glob:
for symbol in decl.mod_sym.syms:
if not symbol.is_public:
continue
self.check_imported_symbol(symbol, decl.pos)
self.source_file.imported_symbols[symbol.name] = symbol
else:
for import_info in decl.import_list:
if import_info.name == "self":
Expand Down

0 comments on commit 6ac11b9

Please sign in to comment.