Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeMismatch when Indexing Bytes / String of different lengths #4166

Open
trocher opened this issue Jun 25, 2024 · 0 comments
Open

TypeMismatch when Indexing Bytes / String of different lengths #4166

trocher opened this issue Jun 25, 2024 · 0 comments

Comments

@trocher
Copy link
Contributor

trocher commented Jun 25, 2024

Version Information

  • vyper Version (output of vyper --version): 0.4.0
  • OS: OSX
  • Python Version (output of python --version): 3.11.4

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.

@trocher trocher changed the title TypeMismatch when Indexing Bytes / String of different length TypeMismatch when Indexing Bytes / String of different lengths Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant