Repository navigation
GROOVY-12521: super.x = value chooses among the setters of the superclass - #3047
Conversation
…lass A property with several setters is a MultipleSetterProperty, whose setProperty calls the setter by name with ordinary dispatch. For super, that reached the class's own setter when it overrides one of them or declares the property: super.x = 'a' set the class's own x in dynamic Groovy and under @TypeChecked, also in a closure and for super.x++ and super.x += v. MetaClassImpl.setProperty now calls the setter as a super call, like super.setX(value).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3047 +/- ##
==================================================
- Coverage 73.6073% 73.6070% -0.0003%
Complexity 42312 42312
==================================================
Files 1657 1657
Lines 145620 145622 +2
Branches 27466 27467 +1
==================================================
+ Hits 107187 107188 +1
+ Misses 28469 28468 -1
- Partials 9964 9966 +2
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 19441c9 Learn more about TestLens at testlens.app/docs. |
daniellansun
left a comment
There was a problem hiding this comment.
Looks correct to me.
MultipleSetterProperty.setProperty always invokes the setter by name through the receiver's metaclass, so super.x = v could not see the superclass overloads. Routing the useSuper case through invokeMethod(..., true, ...) is the smallest fix that reuses ordinary super dispatch, and it matches super.setX(v) / @CompileStatic.
The tests (declare property vs override a setter, both overloads, closures, += / ++) are convincing. +1.
When a superclass overloads a setter (
setX(int)andsetX(String)) and the class overrides one of the setters or declares the property,super.x = vin dynamic Groovy and under@TypeCheckedcalled the class's own setter, also in a closure. It now chooses among the superclass's setters, likesuper.setX(v).@CompileStaticalready did.How
A property with several setters is a
MultipleSetterProperty, whosesetPropertycalls the setter by name with ordinary dispatch, so forsuperit reached the class's own setter.MetaClassImpl.setPropertynow calls the setter as a super call.Tests
groovy.ThisAndSuperTest, for a class that declares the property and one that overrides a setter, in all three modes, and in a closure in dynamic Groovy and under@TypeChecked. They fail without the change. 14,938 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.