vyper icon indicating copy to clipboard operation
vyper copied to clipboard

improve error messages wrt module namespacing

Open pcaversaccio opened this issue 2 years ago • 0 comments

Let's assume you compile modules based on https://github.com/vyperlang/vyper/pull/3663. Furthermore, let's assume we have the following setup:

# Lib.vy

@internal
@pure
def vyper_is_cool_af() -> uint256:
    return 1337

# Main.vy

import Lib

var: uint256

@external
@view
def blocknumber() -> uint256:
    return self.vyper_is_cool_af()

This will throw with:

Error compiling: Main.vy
vyper.exceptions.UndeclaredDefinition: Storage variable 'vyper_is_cool_af' has not been declared.
  contract "Main.vy:10", function "blocknumber", line 10:11
        9 def blocknumber() -> uint256:
  ---> 10     return self.vyper_is_cool_af()
  -------------------^
       11

The issue here is that I mistakenly chose the self keyword instead of Lib. It would be cool if the compiler not only would make suggestions based on the self namespace but also for the imported Lib. Something like:

Error compiling: Main.vy
vyper.exceptions.UndeclaredDefinition: Storage variable 'vyper_is_cool_af' has not been declared. Did you mean 'Lib.vyper_is_cool_af'?
  contract "Main.vy:10", function "blocknumber", line 10:11
        9 def blocknumber() -> uint256:
  ---> 10     return self.vyper_is_cool_af()
  -------------------^
       11

pcaversaccio avatar Dec 15 '23 09:12 pcaversaccio