fix(noirc_frontend): improve error for struct literal in if condition#11557
Merged
TomAFrench merged 4 commits intonoir-lang:masterfrom Feb 20, 2026
Merged
Conversation
Contributor
|
Thank you for your contribution to the Noir language. Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch. Thanks for your understanding. |
asterite
reviewed
Feb 12, 2026
Collaborator
asterite
left a comment
There was a problem hiding this comment.
Thank you, it looks good!
However, can you add a test? There are some existing tests for errors, showing where in the source they happen and what their message (or error kind) is.
Contributor
Author
|
Sure, i will do that. Thank you |
TomAFrench
approved these changes
Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
Resolves #11111
Summary
When a struct literal is used as an
ifcondition (e.g.,if MyStruct { field: true }.field {}),the parser previously produced ~7 confusing, cascading errors. This PR detects the pattern and
emits a single clear diagnostic: "struct literals are not allowed in
ifconditions" with a hintto wrap the struct literal in parentheses.
Additional Context
This matches Rust's behavior for the same ambiguity —
{after the condition is parsed as thestart of the if-then block, not as a struct literal constructor. The fix adds a heuristic in
parse_if_exprthat checks whether the parsed block content looks like struct literal fields(pattern:
ident:after the opening brace), suppresses the misleading cascading errors, andemits a single actionable diagnostic instead.
User Documentation
PR Checklist
cargo fmton default settings.