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: Parse an if followed by a tuple as a block #1924

Merged
merged 2 commits into from
Jul 13, 2023
Merged

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Jul 13, 2023

Description

Problem*

Resolves #1310

Summary*

Previously an if followed by a tuple expression was parsed as a function call, with the return result of the if being the function. This is ambiguous with the grammar of an if expression sequenced with a tuple. Since the later parse is more desirable (and matches what rust does in this scenario) I've resolved the parse by arbitrarily always taking the later over the former.

Since I've added a check when constructing an Expression::call this means unfortunately that any if expression surrounded by parenthesis is also affected. So (if c { f } else { g })(1, 2) is also parsed as a sequence rather than a function call.

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.

@kevaundray
Copy link
Contributor

Does it make sense to include a regression test for this due to it being ambiguous?

@jfecher
Copy link
Contributor Author

jfecher commented Jul 13, 2023

@kevaundray I added a regression test for it in the parser already. I think it does make sense to add one as it also helps document the behavior since it can be easy for it to go unnoticed otherwise.

Edit: Ah, I should actually assert in that test that it parsed a block and not a function call though. I'll update it.

Copy link
Contributor

@kevaundray kevaundray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevaundray kevaundray added this pull request to the merge queue Jul 13, 2023
Merged via the queue into master with commit 8df4f05 Jul 13, 2023
@kevaundray kevaundray deleted the jf/fix-call-parsing branch July 13, 2023 16:29
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.

Parser parses an if statement followed by a tuple as a function call instead of a sequence
2 participants