vyper
vyper copied to clipboard
Ternary operator unable to return `empty` type
Version Information
- vyper Version (output of
vyper --version):0.3.9 - OS:
linux - Python Version (output of
python --version):3.11.3
What's your issue about?
The following snippet will throw the error Exception: Weird code element: ~empty <empty(uint256)>:
@external
@pure
def ceil_div(x: uint256, y: uint256) -> uint256:
assert y != empty(uint256), "Math: ceil_div division by zero"
return empty(uint256) if (x == empty(uint256)) else unsafe_add(unsafe_div(x - 1, y), 1)
To fix it, simply replace empty(uint256) with 0.
@external
@pure
def ceil_div(x: uint256, y: uint256) -> uint256:
assert y != empty(uint256), "Math: ceil_div division by zero"
return 0 if (x == empty(uint256)) else unsafe_add(unsafe_div(x - 1, y), 1)
How can it be fixed?
Allow returning empty type with the ternary operator.
Some minimal repro for the tests when the issue will be fixed:
@external
def foo():
success: address = empty(address) if True else empty(address)