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

bug: Tuple type inference fails with iter.enumerate() #7155

Open
julio4 opened this issue Jan 24, 2025 · 2 comments · May be fixed by #7161
Open

bug: Tuple type inference fails with iter.enumerate() #7155

julio4 opened this issue Jan 24, 2025 · 2 comments · May be fixed by #7161
Labels
bug Something isn't working

Comments

@julio4
Copy link
Contributor

julio4 commented Jan 24, 2025

This should be possible:

for (key, value) in array![0, 1, 2].into_iter().enumerate() {
    assert_eq!(key, value);
}

// Or:
let mut iter = array![0, 1, 2].into_iter().enumerate();
while let Option::Some((k, v)) = iter.next() {
    assert_eq!(k, v);
}

But fails with:

error: Unexpected type for tuple pattern. "?125" is not a tuple.
    for (key, value) in array![0, 1, 2].into_iter().enumerate() {
        ^^^^^^^^^^^^

However this works fine:

for (key, value) in array![(0, 0), (1, 1), (2, 2)].into_iter() {
    assert_eq!(key, value);
}
@julio4 julio4 added the bug Something isn't working label Jan 24, 2025
orizi added a commit that referenced this issue Jan 26, 2025
orizi added a commit that referenced this issue Jan 26, 2025
orizi added a commit that referenced this issue Jan 26, 2025
@a-zmuth
Copy link

a-zmuth commented Feb 6, 2025

May I pick this up? Looks like an interesting problem.

@orizi
Copy link
Collaborator

orizi commented Feb 8, 2025

@a-zmuth what do you know about the inference system? this is a rather complex problem - would really not recommend it as an "good first issue".

this basically requires introducing an actual type for numeric literals - that would have Copy and Drop, and would be implicitly the same as all existing numeric types - so it would be converted into them.

currently the issue is the fact that the .enumerate() result is not fully aware that it is an iterator when .into_iter() is called on it (which happens implicitly by the for) - so at some point it guesses the underlying type of the numeric literal as a felt252 - and then the inference fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants