GEP-16: val keyword for final declarations#2464
Open
paulk-asert wants to merge 1 commit intomasterfrom
Open
Conversation
There was a problem hiding this comment.
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
valand allow it in the same contextual-identifier positions as similar keywords. - Update AST modifier handling so
valimpliesfinal, and add parse-time restrictions wherevalis invalid (e.g., type declarations, method return types). - Add/adjust tests and fixtures for valid/invalid
valusage and fix test code that usedvalas 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.
Contributor
|
+1 |
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.
No description provided.