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

Compiling a function returning an unknown numeric generic panics #6379

Closed
michaeljklein opened this issue Oct 28, 2024 · 2 comments · Fixed by #6405
Closed

Compiling a function returning an unknown numeric generic panics #6379

michaeljklein opened this issue Oct 28, 2024 · 2 comments · Fixed by #6405
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to compile the following program with a function that outputs a numeric generic:

// Using "[(); N]" as a parameter compiles and executes successfully
//
// Using "struct W<N> {}" as a parameter also panics if "foo" is called on "W {}",
// but not if "foo" is called on "let w_1: W<1> = W {};"
fn foo<let N: u32>() -> u32 {
    N
}

fn main() {
    foo();
}

Expected Behavior

The program to compile successfully or fail with a user error

Bug

Compiling the program panics with the following message:

The application panicked (crashed).
Message:  Non-numeric type variable used in expression expecting a value
Location: compiler/noirc_frontend/src/monomorphization/mod.rs:934

To Reproduce

Workaround

Yes

Workaround Description

Use turbofish (e.g. foo::<3>()) to specify numeric generics when they can't be derived from a parameter's type

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.36.0 noirc version = 0.36.0+2f376100d3ee7ab519d6ea30153395bb3e7af7b1 (git version hash: 2f37610, is dirty: false)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the bug Something isn't working label Oct 28, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 28, 2024
@michaeljklein
Copy link
Contributor Author

Could be related to #6126

@jfecher
Copy link
Contributor

jfecher commented Oct 29, 2024

Hmm I had thought we had a check for this case already but it looks like what was added was a slightly different check: #5840. I would've still expected main to error that the generic in the call to foo wasn't known however.

Maybe we need to edit the check_type method that is called to be more stringent.

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Oct 30, 2024
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
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants