Skip to content

Fixes parsing of magic wands#1044

Merged
ArquintL merged 7 commits into
masterfrom
issue-1043
Jul 16, 2026
Merged

Fixes parsing of magic wands#1044
ArquintL merged 7 commits into
masterfrom
issue-1043

Conversation

@ArquintL

Copy link
Copy Markdown
Member

Fixes #1043

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a parser ambiguity introduced by the switch to {...} predicate-constructor arguments: braces following a magic-wand package statement could be parsed as predicate-constructor args of the wand’s RHS expression instead of as the package proof block (issue #1043). The fix tightens the grammar/translation so postfix predicate constructors must end in an explicit selector, preventing {} from attaching to arbitrary primary expressions like P().

Changes:

  • Restrict postfix predicate constructors to primaryExpr . IDENTIFIER { ... } and add a dedicated parenthesized escape form in the grammar.
  • Update parse-tree translation to match the new parse-tree shape for predicate constructors (including parenthesized forms).
  • Add regression and unit tests for selector-ended predicate constructors and the original wand-proof-block regression.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/main/antlr4/GobraParser.g4 Tightens predicate-constructor postfix syntax to require a final selector and adds an explicit parenthesized escape alternative.
src/main/scala/viper/gobra/frontend/ParseTreeTranslator.scala Updates translation logic to construct PPredConstructor only for selector-ended bases and for the new parenthesized escape rule.
src/test/scala/viper/gobra/parsing/ParserUnitTests.scala Adds unit tests to ensure selector-ended (and parenthesized selector-ended) predicate constructors parse as PPredConstructor.
src/test/resources/regressions/issues/001043.gobra Adds a regression program covering the original package P() --* P() {} failure mode and predicate constructors within wands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/resources/regressions/issues/001043.gobra
Comment thread src/test/scala/viper/gobra/parsing/ParserUnitTests.scala
ArquintL and others added 2 commits July 14, 2026 11:24
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/test/resources/regressions/issues/001043.gobra Outdated

@jcp19 jcp19 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just have one question

Comment thread src/main/antlr4/GobraParser.g4 Outdated
Comment on lines +415 to +422
// This postfix form must select the predicate identifier explicitly. Requiring a final selector
// prevents the `{ ... }` of an enclosing construct (for example, a magic-wand package proof block
// after `P() --* P()`) from being consumed as predicate-constructor arguments after an arbitrary
// primary expression. The receiver before the final selector can still be any primary expression.
// Single- and two-component unparenthesized names (`P{...}` and `pkg.P{...}`) are parsed as
// composite literals and disambiguated later. Keep the documented parenthesized escape syntax
// (`(P){...}` and `(pkg.P){...}`) with the same restriction: either a bare predicate name or a
// primary expression with a final selected predicate identifier.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is super verbose and not very clear. Does this impose restrictions on the kinds of predicate instance expressions that one can construct? If so, which kinds of expressions does it disallow? Orienting the comment around that and explaining why those restrictions are in place would make it clear to me (ideally, the comment would also be shorter and more to the point)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure I excelled at making it more concise but the comment clarifies now how we parse predicate constructors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks much better now, thanks!

@jcp19

jcp19 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

LGTM

@ArquintL
ArquintL merged commit 4ccdf62 into master Jul 16, 2026
3 checks passed
@ArquintL
ArquintL deleted the issue-1043 branch July 16, 2026 10:35
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.

Predicate-constructor braces consume magic-wand package proof blocks

3 participants