Repository navigation
GROOVY-12820: SC: a subscript on an inner class instance without getAt uses the getAt of its enclosing instance - #3331
Open
codeconsole wants to merge 2 commits into
Conversation
…ript of an inner class instance without one In an inner class In of Box, where Box has getAt and putAt and In has neither, other[2] for another In reads through Box.getAt on other's enclosing instance in dynamic Groovy and under @TypeChecked, and the type checker accepts it under @CompileStatic too. Code generation then found no getAt on In and failed with GroovyBugError in class generation, for other[2] and for the reads in other[2] += v, other[2]++ and other[2] ?= v. A plain write, other[2] = v, already worked, because static compilation calls putAt dynamically. The subscript writer now follows the receiver's this$0 chain, through a closure's this object where the class was created in a closure, to the first enclosing instance with a getAt, and calls it there; a safe subscript stays null-safe along the chain. A class without an enclosing instance is unchanged.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3331 +/- ##
==================================================
- Coverage 74.9518% 74.9507% -0.0011%
- Complexity 48908 48933 +25
==================================================
Files 1768 1768
Lines 161213 161278 +65
Branches 31728 31747 +19
==================================================
+ Hits 120832 120879 +47
- Misses 28968 28979 +11
- Partials 11413 11420 +7
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 6bcdff1 Learn more about TestLens at testlens.app/docs. |
This branch has not been deployed
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.
In an inner class
InofBox, whereBoxhasgetAtandputAtandInhas neither,other[2]for anotherInreads throughBox.getAtonother's enclosing instance in dynamic Groovy and under@TypeChecked. The type checker accepts it under@CompileStatictoo, but code generation found nogetAtonInand failed withGroovyBugErrorin class generation, forother[2]and for the read inother[2] += v,other[2]++andother[2] ?= v.The subscript writer now follows the receiver's
this$0chain to the first enclosing instance with agetAtand calls it there, through a closure's this object where the class was created in a closure, asOuter.thisdoes. A safe subscript stays null-safe along the chain. A plain write,other[2] = v, already worked, because static compilation callsputAtdynamically. A class without an enclosing instance is unchanged.GROOVY-12820 also describes an inner subclass whose outer class declares private
getAtandputAt, where the compound read usesgetAtonotheritself. On master, static compilation treats that private method as a member ofotherforother.getAt(2)as well, so it is consistent there; #3050 changes that rule and covers the subscript read.Tests
bugs.Groovy12820runs one script dynamically, type checked and statically compiled: a read, a safe read with a receiver and withnull,this[2], a class nested two levels, an anonymous class created in a closure, and the three compound forms. Without the change, the statically compiled run fails with theGroovyBugError. The 18,620 tests in thegroovy,gls,bugs,org.codehaus.groovy.classgen,transform,runtime,reflection,vmplugin,controlandastpackages and the stub generator tests pass.groovy-contracts,groovy-typecheckers,groovy-ginq,groovy-macro-library,groovy-json,groovy-xmlandgroovy-templatespass their tests, and every subproject compiles its main and test sources. The Checkstyle and CodeNarc gates pass.