Skip to content

GEP-16: val keyword for final declarations#2464

Open
paulk-asert wants to merge 1 commit intomasterfrom
valSpike
Open

GEP-16: val keyword for final declarations#2464
paulk-asert wants to merge 1 commit intomasterfrom
valSpike

Conversation

@paulk-asert
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for the new Groovy keyword val (GEP-16) to represent final declarations, including lexer/parser support, AST modifier handling, editor highlighting, and coverage via new core/failure tests.

Changes:

  • Extend ANTLR lexer/parser grammars to recognize val and allow it in the same contextual-identifier positions as similar keywords.
  • Update AST modifier handling so val implies final, and add parse-time restrictions where val is invalid (e.g., type declarations, method return types).
  • Add/adjust tests and fixtures for valid/invalid val usage and fix test code that used val as an identifier in ambiguous positions.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java Adds VAL token to the console editor’s syntax-highlighting keyword list.
src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy Adds failure tests for invalid val constructs.
src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy Adds parser test coverage for a valid val usage script.
src/test/groovy/groovy/transform/stc/LambdaTest.groovy Disambiguates a val field reference (this.val) to avoid conflicts with the new keyword.
src/test/groovy/bugs/Groovy5358.groovy Renames a test property from val to stored to avoid keyword conflicts.
src/test-resources/fail/Val_01x.groovy New fixture asserting val cannot be used for type declarations.
src/test-resources/fail/Val_02x.groovy New fixture asserting val cannot be used for method return types/declarations.
src/test-resources/fail/Val_03x.groovy New fixture asserting reassignment to a val variable fails.
src/test-resources/core/Val_01x.groovy New fixture covering valid val usage patterns (including contextual keyword behavior).
src/main/java/org/codehaus/groovy/ast/ModifierNode.java Maps VAL to ACC_FINAL and exposes isVal().
src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java Adds val-related validation and updates modifier checks to include VAL.
src/antlr/GroovyParser.g4 Adds VAL to modifier/variableModifier/indexVariable/identifier/keywords rules.
src/antlr/GroovyLexer.g4 Introduces VAL : 'val'; token.

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

@daniellansun
Copy link
Copy Markdown
Contributor

daniellansun commented Apr 12, 2026

+1

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.

3 participants