vyperlang / vyper

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

`TypeMismatch` when Indexing `Bytes` / `String` of different lengths #4166

Open trocher opened 1 week ago

trocher commented 1 week ago

Version Information

What's your issue about?

When Indexing Bytes or String of different length, depending on the order of the elements in the List it can be that the compiler incorrectly fails to type check.

Most likely related to #4079, #3253

@external
def foo():
    index: uint256 = 1
    a: String[30] = ""
    b: String[257] = ""
    l1: String[257] = [b,a][index] # compiles
    l2: String[257] = [a,b][index] # does not compile
vyper.exceptions.TypeMismatch: Expected String[30][2] but literal can only be cast as DynArray[String[30], 2] or String[30][2].

h/t @ritzdorf

How can it be fixed?

Probably by fixing compare_type for Bytes and Strings.