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

Invalid array length errors do not print source location #3150

Closed
ghost opened this issue Nov 14, 2022 · 3 comments
Closed

Invalid array length errors do not print source location #3150

ghost opened this issue Nov 14, 2022 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 14, 2022

Version Information

  • vyper Version (output of vyper --version): 0.3.7
  • OS: macOS 12.6
  • Python Version (output of python --version): 3.10.5

What's your issue about?

Whereas most other compile-time issues show the offending source line from the contract, compiling a dynamic array with an invalid size only shows an error with the source file name. Showing the line would help in searching and correcting typos or other issues causing the bad length value.

Super short example:

# @version 0.3.7

owner: public(address)
example: public(DynArray[int8, 0])

@external
def __init__():
	self.owner = msg.sender

CLI output:

> vyper ~/Desktop/example.vy
Error compiling: /Users/ibis/Desktop/example.vy
vyper.exceptions.InvalidType: Array length is invalid

[9171] Failed to execute script 'vyper_compile' due to unhandled exception!

How can it be fixed?

Ideally when this issue occurs the compiler should print out the offending line like it does with other errors. For example if I were to deliberately cause an error in __init__() it displays the offending source:

# @version 0.3.7

owner: public(address)

@external
def __init__():
	example: DynArray[int8, 1] # missing value!
	self.owner = msg.sender
> vyper ~/Desktop/example.vy
Error compiling: /Users/ibis/Desktop/example.vy
vyper.exceptions.VariableDeclarationException: Memory variables must be declared with an initial value
  contract "/Users/ibis/Desktop/example.vy:7", function "__init__", line 7:1 
       6 def __init__():
  ---> 7 	example: DynArray[int8, 1] # missing value!
  --------^
       8 	self.owner = msg.sender

[9646] Failed to execute script 'vyper_compile' due to unhandled exception!
@ghost
Copy link
Author

ghost commented Nov 16, 2022

A similar issue seems to occur for immutables referenced with self:

# @version 0.3.7
# test.vy

DATA: immutable(uint256)

@external
def __init__(_data: uint256):
    self.DATA = _data   # this line should be shown in the error output
> vyper test.vy
Error compiling: test.vy
vyper.exceptions.SyntaxException: Immutable variables must be accessed without 'self'
[41858] Failed to execute script 'vyper_compile' due to unhandled exception!

@emc415
Copy link
Contributor

emc415 commented Jan 12, 2023

hi @helloibis! I created a PR to address the first example you posted.

Regarding the second example with self.DATA = _data: when I run it now I do get a pointer to the line in the src code. Please let me know if you also do!

As it stands, the pointer is to line 1 as opposed to line 5, but at least there is one. I played around with adjusting it to line 5, but it appears to be a bit complicated. Do you think it's important?

Cheers!

@charles-cooper
Copy link
Member

this was fixed in #3663 (by the tag_exceptions() machinery).

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

Successfully merging a pull request may close this issue.

2 participants