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

fix[ux]: fix error message for common typo #4363

Closed

Conversation

charles-cooper
Copy link
Member

the staticall typo is very common, and was raising a hard-to-read error message from the python parser like "invalid syntax. Perhaps you forgot a comma?"

this commit adds it to the pre-parser, so we can raise an exception after we have successfully gone through the python parser and have the ability to add source info and a hint.

What I did

How I did it

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

the `staticall` typo is very common, and was raising a hard-to-read
error message from the python parser like "invalid syntax. Perhaps you
forgot a comma?"

this commit adds it to the pre-parser, so we can raise an exception
after we have successfully gone through the python parser and have the
ability to add source info and a hint.
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.46%. Comparing base (c32b9b4) to head (2eac70d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4363      +/-   ##
==========================================
- Coverage   91.23%   90.46%   -0.78%     
==========================================
  Files         112      112              
  Lines       16010    16012       +2     
  Branches     2697     2698       +1     
==========================================
- Hits        14607    14485     -122     
- Misses        968     1072     +104     
- Partials      435      455      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

compile_code(bad_code)


def test_bad_staticcall_keyword():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test contract itself is incomplete. Can we make sure we unit test only the introduced change here?

A correct (i.e. compileable) Vyper contract would look like this

from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed


@external
def foo():
    extcall IERC20(msg.sender).transfer(
        msg.sender,
        convert(staticcall IERC20Detailed(msg.sender).decimals(), uint256),
    )

so we could have the following here:

from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed


@external
def foo():
    extcall IERC20(msg.sender).transfer(
        msg.sender,
        convert(staticall IERC20Detailed(msg.sender).decimals(), uint256),
    )

Another example with nested staticcall could be:

from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed


@view
def bar() -> uint256:
    return staticcall IERC20(msg.sender).balanceOf(
        convert(staticall IERC20Detailed(msg.sender).decimals(), address)
    )

In the last example, if you replace view with pure, it will raise the staticcall first instead of:

vyper.exceptions.StateAccessViolation: Cannot call a view function from a pure function

which is the expected behaviour IMO.

CUSTOM_EXPRESSION_TYPES = {
"extcall": "ExtCall",
"staticcall": "StaticCall",
"staticall": "BadStaticCall", # common typo - we parse it to AST for better error reporting
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some other (not so common, but still) typos are:

  • staticcal (that one we should probably also cover)
  • statiiccall
  • stacticall
  • staticcal

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although I can imagine such mistakes being made, I don't like the idea that we would reserve 5 keywords just for error reporting (though I don't think such keywords would be used by users anyway)

@cyberthirst
Copy link
Collaborator

cyberthirst commented Nov 23, 2024

very unlikely.. but for completness

staticall: uint256
vyper.exceptions.SyntaxException: invalid syntax (<unknown>, line 1)

  line 1:10 
  ---> 1 staticall: uint256
  -----------------^
       2

or

def staticall():
    pass

yieds same the same ex

edit: added examples

@charles-cooper
Copy link
Member Author

@cyberthirst raised offline -- could we preprocess the error message to look for the typo instead of reserving a keyword?

@charles-cooper charles-cooper added this to the v0.4.1 milestone Dec 19, 2024
@charles-cooper charles-cooper self-assigned this Dec 30, 2024
@charles-cooper charles-cooper changed the title fix[ux]: fix error message for common typo fix[ux]: fix error message for staticall typo Jan 5, 2025
@charles-cooper charles-cooper changed the title fix[ux]: fix error message for staticall typo fix[ux]: fix error message for common typo Jan 5, 2025
@charles-cooper charles-cooper marked this pull request as draft January 8, 2025 15:54
@charles-cooper
Copy link
Member Author

closing in favor of #4438

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 this pull request may close these issues.

4 participants