vyper
vyper copied to clipboard
bug: incorrect typing for builtin functions whose return type depends on its arguments' types
Version Information
- vyper Version (output of
vyper --version): https://github.com/vyperlang/vyper/commit/9e3b9a2b8ae55aa83b5450080f750be15f819de7 - OS: linux
- Python Version (output of
python --version): 3.10.4
What's your issue about?
Builtin functions whose return type depends on some of its argument's type can be incorrectly typed resulting in the compiler exiting with a TypeMismatch.
To trigger this behavior, call the builtin function with arguments such that:
- at least one argument is not constant (as the call would be folded otherwise)
get_possible_types_from_nodeshould return multiple potential types for this arguments on which the return type of the builtin function depends.
Affected builtins:
minandmax:a: uint256 = min(1 if True else 2, 1)- all unsafe builtins:
a: uint256 = unsafe_add(1 if True else 2, 1) shift(deprecated as of v0.3.8):a: uint256 = shift(-1, 1 if True else 2)uint2str:f: String[12] = uint2str(1 if True else 2)
h/t @trocher
How can it be fixed?
Fill this in if you know how to fix it.
Other example:
@external
@payable
def foo():
x:uint256 = 1
a:uint256 = min([1,2][x], 1)
vyper.exceptions.TypeMismatch: Given reference has type int8, expected uint256
(Also for reference still an issue as of 0.3.10)
note: several of these are resolved as of v0.4.0b1 (b53a020c74857de33cf4fd1a6d24a398539758b1) but some still will not compile.