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

fix: Prevent if and for from parsing constructor expressions #1916

Merged
merged 2 commits into from
Jul 13, 2023

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Jul 12, 2023

Description

Problem*

In the code:

if x {
    y
} else {
    z
}

The parser would parse an expression for the if condition and x { y } is a valid constructor expression using the shorthand field syntax. I've resolved this to more closely follow rust's official grammar (https://doc.rust-lang.org/reference/expressions/if-expr.html) in which constructor expressions are forbidden as part of an if condition:

image

Note the "except struct expression" subscript.

Resolves #1915 and #152

Summary*

Unfortunately this PR is quite messy. I'm not sure of a good way to clean it up at the moment without duplicating the expression parser. Chumsky requiring us to pass each recursive parser as a parameter makes it quite a bit more verbose.

Documentation

  • This PR requires documentation updates when merged.

    • I will submit a noir-lang/docs PR.
    • I will request for and support Dev Rel's help in documenting this PR.

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher jfecher changed the title Prevent if and for from parsing constructor expressions Prevent if and for from parsing constructor expressions Jul 12, 2023
@jfecher jfecher changed the title Prevent if and for from parsing constructor expressions fix: Prevent if and for from parsing constructor expressions Jul 12, 2023
@kevaundray kevaundray added this pull request to the merge queue Jul 13, 2023
Merged via the queue into master with commit 6d3029a Jul 13, 2023
@kevaundray kevaundray deleted the jf/parse-ifs branch July 13, 2023 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

if-then blocks containing a single variable give a parse error
2 participants