cairo icon indicating copy to clipboard operation
cairo copied to clipboard

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

Open julio4 opened this issue 11 months ago • 6 comments

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 avatar Jan 24 '25 15:01 julio4

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

a-zmuth avatar Feb 06 '25 22:02 a-zmuth

@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.

orizi avatar Feb 08 '25 10:02 orizi

May I try? Might take longer as I'm first time contributor, but I'm interested and have a good track record!

baitcode avatar Feb 18 '25 17:02 baitcode

I think it is less relevant a a first time contributor - and we are already on it.

orizi avatar Feb 18 '25 18:02 orizi

Hi, I am proficient Blockchain developer expert in Cairo , Rust and Solidity and also in web development. I have contributed many starknet ,stellar projects and more . please /assign Me this issue . Thank You !!

ryzen-xp avatar Feb 19 '25 06:02 ryzen-xp

as stated in the my previous comment - we are already on it. not going to assign this to anyone out of the core-team.

orizi avatar Feb 19 '25 08:02 orizi