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

(fuzzer) - should the parser allow constructors in parentheses within if condition and for range? #2996

Closed
pczarn opened this issue Oct 5, 2023 · 3 comments · Fixed by #3219
Assignees
Labels
bug Something isn't working

Comments

@pczarn
Copy link
Contributor

pczarn commented Oct 5, 2023

Aim

Tried to parse the following code:

fn foo() {
  let x = Bar  { baz : 1 };
  if (Bar { baz: 1 } == Bar { baz: 2 }) {
    // do something
  }
}

Expected Behavior

I know that constructors appearing directly after if and for ... in are disallowed, but I expected the code to parse and compile OK because the constructors are surrounded by parentheses.

Bug

Got parse error Expected an expression but found {.

This behavior is inconsistent with Rust lang, which allows the code to compile. Also, it does not quite make sense to disallow such syntax.

Most likely reason for the bug is the second argument to expression_with_precedence called from expression_no_constructors:

fn expression_no_constructors() -> impl ExprParser {
    recursive(|expr| {
        expression_with_precedence(Precedence::Lowest, expr.clone(), expr, false, false)
    })
    .labelled(ParsingRuleLabel::Expression)
}

Installation Method

Compiled from source

Additional Context

Found by the parser-fuzzer tool.

Would you like to submit a PR for this Issue?

Yes, possible

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

pczarn commented Oct 5, 2023

Seems important because formal grammar is much worse with two kinds of expression inside, those allowing constructors and those that do not.

@pczarn
Copy link
Contributor Author

pczarn commented Oct 5, 2023

I have code that may fix this.

pczarn added a commit to pczarn/noir that referenced this issue Oct 18, 2023
pczarn added a commit to pczarn/noir that referenced this issue Oct 18, 2023
@jfecher
Copy link
Contributor

jfecher commented Oct 18, 2023

Yes, we should allow it. It was an oversight that it was not already allowed.

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Oct 18, 2023
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
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants