noir-lang / noir

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

Integers in attribute arguments are always passed as `Field`s #6373

Open jfecher opened 1 week ago

jfecher commented 1 week ago

Aim

#[foo(32)]
comptime fn foo(_f: FunctionDefinition, i: u32) {
    println(std::meta::type_of(i));
}

fn main() {}

Expected Behavior

u32 to be printed

Bug

Field is printed, and if we use i in an operation with a u32, e.g. i == x we'll get an error that we can't perform an equality on a Field and a u32.

To Reproduce

1. 2. 3. 4.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

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

asterite commented 1 week ago

I'm not sure what's the best way to solve this.

Right now we check that the types unify, but the value we pass doesn't change. So if we pass a Value::Field it remains a Field.

We could cast that value to the target type, though that would only work for primitive types. That said, you can't pass an array in an attribute because right now it doesn't parse... but I guess we'd eventually want to support that.

jfecher commented 1 week ago

@asterite I'm not sure on a good way either. I suppose we'd have to pass down an expected type when creating the attribute arguments to begin with.