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

if block in for loop crashes test #2787

Closed
bryanwee023 opened this issue Sep 22, 2023 · 1 comment · Fixed by #2796
Closed

if block in for loop crashes test #2787

bryanwee023 opened this issue Sep 22, 2023 · 1 comment · Fixed by #2796
Assignees
Labels
bug Something isn't working ssa

Comments

@bryanwee023
Copy link

bryanwee023 commented Sep 22, 2023

Aim

I want to achieve something similar to this logic flow:

let mut v = Vec::new();
let mut skip = true;
for _ in 0..5 {
    if skip {
        v.push(1);
        // Do something to skip here...
    } 
}

Expected Behavior

The block of code to run. Or if the operation is not supported (for some reason), then maybe a more appropriate error message should be printed.

Bug

I get the following output error:

[noir_playground] Testing test_main... The application panicked (crashed).
Message:  Expected array value

To Reproduce

This is the minimal example I managed to find.

use dep::std::collections::vec::Vec;

fn main() {
    let mut v = Vec::new();

    let mut skip = true;
    for _ in 0..5 {
        if skip {
            v.push(1);
        }
    }
}

#[test]
fn test_main() {
    main();
}

Calling nargo test will produce the error.
Some things I noted:

  1. Removing the vector v fixes things
  2. Removing the if condition fixes things
  3. Using a different condition for if (e.g., a bool declared outside main fixes things)

Installation Method

Binary

Nargo Version

nargo 0.10.5 (git version hash: 91efe44, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@bryanwee023 bryanwee023 added the bug Something isn't working label Sep 22, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 22, 2023
@jfecher
Copy link
Contributor

jfecher commented Sep 22, 2023

The error given in your snippet no longer occurs, but we do run into a different "attempt to subtract with underflow" panic. I've made a PR to fix it here: #2796

@jfecher jfecher self-assigned this Sep 22, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ssa
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants