vyperlang / vyper

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

bug: incorrect typing for builtin functions whose return type depends on its arguments' types #3513

Open tserg opened 1 year ago

tserg commented 1 year ago

Version Information

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:

  1. at least one argument is not constant (as the call would be folded otherwise)
  2. get_possible_types_from_node should return multiple potential types for this arguments on which the return type of the builtin function depends.

Affected builtins:

h/t @trocher

How can it be fixed?

Fill this in if you know how to fix it.

trocher commented 1 year ago

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)

charles-cooper commented 8 months ago

note: several of these are resolved as of v0.4.0b1 (b53a020c74857de33cf4fd1a6d24a398539758b1) but some still will not compile.