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

Field computed to be larger than u32::MAX with arithmetic generics panics #6126

Open
michaeljklein opened this issue Sep 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to compile a program that adds two Field's using arithmetic generics, where the result of the computation is larger than u32::MAX:

struct Foo<let F: Field> {}

impl<let F: Field> Foo<F> {
    fn size(self) -> Field {
        F
    }
}

// 2^32 - 1
global A: Field = 4294967295;

// Avoiding overflow succeeds:
// fn foo<let A: Field>() -> Foo<A> {
fn foo<let A: Field>() -> Foo<A + A> {
    Foo {}
}

fn main() {
    // skipping 'size()' succeeds
    let C = foo::<A>();
    let C = foo::<A>().size();
}

Note that using a u64 instead of a Field fails with:

error: The only supported numeric generic types are `u1`, `u8`, `u16`, and `u32`
  ┌─ src/main.nr:5:12
  │
5 │ struct Foo<let F: u64> {}
  │            ----------
  │

Expected Behavior

Expected compilation to succeed or else fail with a user-error

Bug

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

This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.
If there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.34.0 noirc version = 0.34.0+5598059576c6cbc72474aff4b18bc5e4bb9f08e1 (git version hash: 5598059, 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 Sep 23, 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: 📋 Backlog
Development

No branches or pull requests

1 participant