vyperlang / vyper

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

initialisation of stateless modules #3934

Open pcaversaccio opened 5 months ago

pcaversaccio commented 5 months ago

Not sure whether this is a bug or feature, but the initialisation of stateless modules compiles:

# lib.vy
@deploy
@payable
def __init__():
    pass

@internal
@pure
def _uint256_average(x: uint256, y: uint256) -> uint256:
    return unsafe_add(x & y, (x ^ y) >> 1)

# main.vy
import lib
initializes: lib

@deploy
def __init__():
    lib.__init__()

@external
@pure
def uint256_average(x: uint256, y: uint256) -> uint256:
    return lib._uint256_average(x, y)
fubuloubu commented 5 months ago

seems like it should just emit a warning about it not really being neccessary to do

charles-cooper commented 5 months ago

i'd say if we're going to issue a warning, we might as well issue an error. initializing a stateless module seems like an error tbh. (i think in most languages it would be considered a linter issue, but in vyper we have always been a bit more aggressive about promoting "lint-level" issues into compiler errors).

pcaversaccio commented 5 months ago

I think disallowing this behaviour makes most sense, i.e. throw a compiler error.