vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.84k stars 788 forks source link

Immutables Allowed to Be Used as Default Arguments #3932

Open cyberthirst opened 5 months ago

cyberthirst commented 5 months ago

Version Information

According to the documentation, the default arguments of a function must be literals or environment variables, however, immutables are allowed to be used as default arguments.

The following contract compiles:

x:immutable(uint256)

@deploy
def __init__():
    x = 1

@external
def foo(val:uint256 = x):
    pass

credits: @trocher

fubuloubu commented 5 months ago

this seems kinda useful actually, suggest updating docs?

charles-cooper commented 5 months ago

i'm not sure yet if this is a compiler bug or docs issue, but i'm leaning towards docs issue.

note that this behavior was introduced in https://github.com/vyperlang/vyper/pull/3669, and that this behavior is blocked for pure functions as of https://github.com/vyperlang/vyper/pull/3895 (pure cannot read from runtime code, but view can)