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: thread panic "missing function core::array::ArrayIterator::<core::integer::u8>::advance_by" #7031

Closed
cairoIover opened this issue Jan 8, 2025 · 0 comments · Fixed by #7045
Labels
bug Something isn't working

Comments

@cairoIover
Copy link
Contributor

Bug Report

Cairo version:
6e8795a

Current behavior:
Trying to implement advance_by after #7027 was merged:

/// An iterator over a collection of values.
pub trait Iterator<T> {
    /// The type of the elements being iterated over.
    type Item;

    /// Advance the iterator and return the next value.
    fn next(ref self: T) -> Option<Self::Item>;

    fn advance_by(ref self: T, n: usize) -> Result<(), NonZero<usize>> {
        let mut res = Result::Ok(());
        for i in 0..n {
            if Self::next(ref self).is_none() {
                res = Result::Err((n - i).try_into().unwrap());
                break;
            }
        };
        res
    }
}

Added an associated test:

#[test]
fn test_advance_by() {
    let a = array![1_u8, 2, 3, 4];
    let mut iter = a.into_iter();

    assert_eq!(iter.advance_by(2), Result::Ok(()));
    assert_eq!(iter.next(), Option::Some(3));
    assert_eq!(iter.advance_by(0), Result::Ok(()));
}

The implementation of Iterator stays the same: it should leverage the default trait impl

impl ArrayIterator<T> of Iterator<ArrayIter<T>> {
    /// The type of the elements being iterated over.
    type Item = T;
    /// Advances the iterator and returns the next value. Returns `Option::None` when iteration is
    /// finished.
    fn next(ref self: ArrayIter<T>) -> Option<T> {
        self.array.pop_front()
    }
}

Running the tests panics with:

thread '<unnamed>' panicked at crates/cairo-lang-sierra-generator/src/utils.rs:331:13:
Missing function core::array::ArrayIterator::<core::integer::u8>::advance_by
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at crates/cairo-lang-sierra-generator/src/utils.rs:331:13:
Missing function core::array::ArrayIterator::<core::integer::u8>::advance_by

Expected behavior:
The test should run successfully - or a clear error message returned

@cairoIover cairoIover added the bug Something isn't working label Jan 8, 2025
orizi added a commit that referenced this issue Jan 12, 2025
…ics of trait fn bodies.

Fixes #7031
Fixes #7038

commit-id:c29f1286
orizi added a commit that referenced this issue Jan 12, 2025
…ics of trait fn bodies.

Fixes #7031
Fixes #7038

commit-id:c29f1286
orizi added a commit that referenced this issue Jan 12, 2025
…ics of trait fn bodies.

Fixes #7031
Fixes #7038

commit-id:c29f1286
orizi added a commit that referenced this issue Jan 12, 2025
…ics of trait fn bodies.

Fixes #7031
Fixes #7038

commit-id:c29f1286
orizi added a commit that referenced this issue Jan 12, 2025
…ics of trait fn bodies.

Fixes #7031
Fixes #7038

commit-id:c29f1286
orizi added a commit that referenced this issue Jan 12, 2025
…ics of trait fn bodies.

Fixes #7031
Fixes #7038

commit-id:c29f1286
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
1 participant