noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
831 stars 179 forks source link

Numeric generic struct parameter panics when accessed uninitialized #5436

Open michaeljklein opened 1 week ago

michaeljklein commented 1 week ago

Aim

Attempted to compile the following program:

struct Foo<let N: u32> { }

impl<let N: u32> Foo<N> {
    fn size(self) -> u32 {
        N
    }
}

fn main() {
    let foo = Foo { };
    assert(foo.size() == 0);
}

Expected Behavior

Expected the program to either compile successfully (having defaulted N = 0) or fail with a user error because N is uninitialized when declaring foo.

Bug

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

To Reproduce

1. 2. 3. 4.

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

None

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

vezenovm commented 1 week ago

fail with a user error because N is uninitialized when declaring foo.

Yeah I think we should fail with that a type annotation is needed here.