Skip to content

Commit

Permalink
fix duplicate initialization check, rename FunctionNodeVisitor to Fun…
Browse files Browse the repository at this point in the history
…ctionAnalyzer
  • Loading branch information
charles-cooper committed Feb 3, 2024
1 parent 82e1da0 commit 9d94161
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 2 additions & 4 deletions vyper/builtins/_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from vyper.ast import parse_to_ast
from vyper.codegen.context import Context
from vyper.codegen.stmt import parse_body
from vyper.semantics.analysis.local import FunctionNodeVisitor
from vyper.semantics.analysis.local import FunctionAnalyzer

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.analysis.local
begins an import cycle.
from vyper.semantics.namespace import Namespace, override_global_namespace
from vyper.semantics.types.function import ContractFunctionT, FunctionVisibility, StateMutability
from vyper.semantics.types.module import ModuleT
Expand All @@ -25,9 +25,7 @@ def generate_inline_function(code, variables, variables_2, memory_allocator):
ast_code.body[0]._metadata["func_type"] = ContractFunctionT(
"sqrt_builtin", [], [], None, FunctionVisibility.INTERNAL, StateMutability.NONPAYABLE
)
# The FunctionNodeVisitor's constructor performs semantic checks
# annotate the AST as side effects.
analyzer = FunctionNodeVisitor(ast_code, ast_code.body[0], namespace)
analyzer = FunctionAnalyzer(ast_code, ast_code.body[0], namespace)
analyzer.analyze()

new_context = Context(
Expand Down
4 changes: 2 additions & 2 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def validate_functions(vy_module: vy_ast.Module) -> None:
for node in vy_module.get_children(vy_ast.FunctionDef):
with namespace.enter_scope():
try:
analyzer = FunctionNodeVisitor(vy_module, node, namespace)
analyzer = FunctionAnalyzer(vy_module, node, namespace)
analyzer.analyze()
except VyperException as e:
err_list.append(e)
Expand Down Expand Up @@ -179,7 +179,7 @@ def _validate_self_reference(node: vy_ast.Name) -> None:
raise StateAccessViolation("not allowed to query self in pure functions", node)


class FunctionNodeVisitor(VyperNodeVisitorBase):
class FunctionAnalyzer(VyperNodeVisitorBase):
ignored_types = (vy_ast.Pass,)
scope_name = "function"

Expand Down
11 changes: 6 additions & 5 deletions vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ def _collect_initialized_modules_r(module_t, seen=None):
initialized_infos = module_t.initialized_modules

for i in initialized_infos:
if (other := seen.get(i.module_info.module_t)) is not None:
raise StructureException("{i.module_info.alias} initialized twice!", i.node, other)
seen[i.module_info.module_t] = i
initialized_module_t = i.module_info.module_t
if initialized_module_t in seen:
seen_nodes = (i.node, seen[initialized_module_t].node)
raise StructureException(f"`{i.module_info.alias}` initialized twice!", *seen_nodes)
seen[initialized_module_t] = i

for d in i.dependencies:
_collect_initialized_modules_r(d.module_t, seen)
_collect_initialized_modules_r(initialized_module_t, seen)

return seen

Expand Down

0 comments on commit 9d94161

Please sign in to comment.