Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: semantic analysis of imported contract is done with current contract's namespace #3519

Closed
tserg opened this issue Jul 19, 2023 · 1 comment

Comments

@tserg
Copy link
Collaborator

tserg commented Jul 19, 2023

Version Information

  • vyper Version (output of vyper --version): 9e3b9a2
  • OS: linux
  • Python Version (output of python --version): 3.10.4

What's your issue about?

When an imported interface is typed, the namespace of the current contract is used to generate the interface type from the AST of the imported contract. This means that the imported contract's function definitions may use the types and constants defined in the current contract. For example a.vy would compile successfully although b.vy, which is imported by a.vy makes use of S and a, both defined in a.vy.

# a.vy

import b as B

struct S:
    x: uint256

a: constant(uint256) = 12

@external
def bar(addr: address):
    x: B = B(addr)
    y: S = x.foo()
# b.vy

@external
def foo(a: uint256 = a) -> S:
    return S({x: 12})

h/t @trocher

How can it be fixed?

Fill this in if you know how to fix it.

@charles-cooper
Copy link
Member

this was fixed in #3663. compiling a.vy now results in

Error compiling: a.vy
vyper.exceptions.UndeclaredDefinition: 'a' has not been declared. 
  contract "b.vy:4", function "foo", line 4:21 
       3 @external
  ---> 4 def foo(a: uint256 = a) -> S:
  ----------------------------^
       5     return S({x: 12})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants