vyper icon indicating copy to clipboard operation
vyper copied to clipboard

Immutables Allowed to Be Used as Default Arguments

Open cyberthirst opened this issue 10 months ago • 2 comments

Version Information

  • vyper Version (output of vyper --version): commit 4b4e188ba83d28b5dd6ff66479e7448e5b925030

Issue description

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

cyberthirst avatar Apr 10 '24 11:04 cyberthirst

this seems kinda useful actually, suggest updating docs?

fubuloubu avatar Apr 10 '24 17:04 fubuloubu

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)

charles-cooper avatar Apr 10 '24 17:04 charles-cooper