vyper icon indicating copy to clipboard operation
vyper copied to clipboard

initialisation of stateless modules

Open pcaversaccio opened this issue 10 months ago • 3 comments

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)

pcaversaccio avatar Apr 10 '24 12:04 pcaversaccio

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

fubuloubu avatar Apr 10 '24 17:04 fubuloubu

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).

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

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

pcaversaccio avatar Apr 10 '24 18:04 pcaversaccio