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

Add explicit error message when specifying default_return_value on void function call #3121

Merged
merged 5 commits into from
Nov 8, 2022

Conversation

benber86
Copy link
Contributor

What I did

When specifying the default_return_value on a call to a void external function, the compiler currently only returns the following error message AttributeError: 'NoneType' object has no attribute 'compare_type'.
I added a more explicit exception so that the error can be caught and addressed more easily.

How I did it

I added a check for a return type when default_return_value is set. If there's no return type, an ArgumentException is raised.

How to verify it

Compiling this contract:

interface FooBar:
    def foo(): payable

@external
def bar():
    FooBar(empty(address)).foo(default_return_value=True)

will now generate the following error:

vyper.exceptions.ArgumentException: default_return_value specified but foo is void
  contract "dist/simple.vy:6", function "bar", line 6:52 
       5 def bar():
  ---> 6     FooBar(empty(address)).foo(default_return_value=True)
  -----------------------------------------------------------^
       7

Commit message

Exception when setting default_return_value on void function call

Description for the changelog

Add explicit error message when specifying default_return_value on void function call

Cute Animal Picture

image

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

is there any case where require_return= should not be set to true?

@benber86
Copy link
Contributor Author

is there any case where require_return= should not be set to true?

Not for the default_return_value kwarg specifically. Would you prefer something like if kwarg.arg == "default_return_value" over having a flag for it?

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2022

Codecov Report

Merging #3121 (c575665) into master (6020b8b) will decrease coverage by 0.27%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #3121      +/-   ##
==========================================
- Coverage   88.49%   88.21%   -0.28%     
==========================================
  Files          95       95              
  Lines       10758    10762       +4     
  Branches     2554     2267     -287     
==========================================
- Hits         9520     9494      -26     
- Misses        796      829      +33     
+ Partials      442      439       -3     
Impacted Files Coverage Δ
vyper/semantics/types/function.py 86.51% <0.00%> (-0.66%) ⬇️
vyper/codegen/arithmetic.py 79.48% <0.00%> (-5.13%) ⬇️
vyper/semantics/types/value/numeric.py 80.45% <0.00%> (-4.60%) ⬇️
vyper/builtin_functions/functions.py 89.23% <0.00%> (-1.31%) ⬇️
vyper/compiler/output.py 89.06% <0.00%> (+0.05%) ⬆️
vyper/cli/vyper_json.py 79.09% <0.00%> (+0.07%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
@charles-cooper charles-cooper enabled auto-merge (squash) November 1, 2022 15:26
@charles-cooper charles-cooper merged commit 9c3b2c4 into vyperlang:master Nov 8, 2022
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