You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tried to distill it to a minimal example, but it was a complicated bit of aztec3 code i was writing.
I've tested this not very minimal example (but as minimal as I could cause the error) with v0.4.1. It's a horrible example. The code was doing lots of stuff, and I just started stripping things out whilst trying to retain the error.
NOTICE: when we remove the constrain liine, it causes this error. If we reinstate the constrain line, the error disappears. Not sure why I need a constrain here.
fn main(a: Field, condition: bool) -> pub bool {
let (b, arr) = foo(a, condition);
arr[0] == 4 + b
}
fn foo(a: Field, condition: bool) -> (Field, [Field; 2]) {
let mut arr: [Field; 2] = [1, 2];
if condition {
arr[0] = a;
} else {
arr[0] = 4;
}
// NOTICE: no idea why I need this constraint here... or what the error means when you remove it.
// constrain arr[0] == 4;
(a, arr)
}
error: Expected a function, but found a(n) ()
┌─ /mnt/user-data/mike/packages/yarn-project/noir-contracts/src/contracts/mike-play/src/main.nr:11:5
│
11 │ ╭ if condition {
12 │ │ arr[0] = a;
13 │ │ } else {
14 │ │ arr[0] = 4;
15 │ │ }
16 │ │ // TODO: no idea why I need this constraint here... or what the error means when you remove it.
17 │ │ // constrain arr[0] == 4;
18 │ │
19 │ │ (a, arr)
│ ╰────────────'
error: aborting due to 1 previous errors
Error: Failed to compile circuit
Location:
crates/nargo_cli/src/cli/mod.rs:71:5
```
### Expected behavior
.
### Bug
.
### To reproduce
1.
2.
3.
4.
### Installation method
None
### Nargo version
_No response_
### @noir-lang/noir_wasm version
_No response_
### @noir-lang/barretenberg version
_No response_
### @noir-lang/aztec_backend version
_No response_
### Additional context
_No response_
### Submission Checklist
- [ ] Once I hit submit, I will assign this issue to the Project Board with the appropriate tags.
The text was updated successfully, but these errors were encountered:
This is an interesting one. It is parsing the whole expression as a function call:
if condition {
arr[0] = a;}else{
arr[0] = 4;}(a, arr)
Hence why the constrain statement with its semicolon afterwards fixes it. I may have to look at the rust grammar a bit for this one since this is technically an ambiguous parse, but the right solution should be to restructure the parser a bit to favor them as two separate statements.
jfecher
changed the title
Error: Expected a function, but found a(n) ()
Parser parses an if statement followed by a tuple as a function call instead of a sequence
Jul 13, 2023
Aim
I've tried to distill it to a minimal example, but it was a complicated bit of aztec3 code i was writing.
I've tested this not very minimal example (but as minimal as I could cause the error) with v0.4.1. It's a horrible example. The code was doing lots of stuff, and I just started stripping things out whilst trying to retain the error.
NOTICE: when we remove the
constrain
liine, it causes this error. If we reinstate theconstrain
line, the error disappears. Not sure why I need aconstrain
here.The text was updated successfully, but these errors were encountered: