Repository navigation
GROOVY-12609: STC: resolve the remapped name of a super trait field in a closure or for an instance field - #3136
codeconsole wants to merge 2 commits into
Conversation
…n a closure or for an instance field
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3136 +/- ##
==================================================
+ Coverage 74.1016% 74.4132% +0.3116%
- Complexity 43596 44388 +792
==================================================
Files 1692 1699 +7
Lines 149245 151078 +1833
Branches 28284 28792 +508
==================================================
+ Hits 110593 112422 +1829
+ Misses 28475 28378 -97
- Partials 10177 10278 +101
🚀 New features to boost your workflow:
|
daniellansun
left a comment
There was a problem hiding this comment.
LGTM for GROOVY-12609.
Remapped super-trait field names (T__shared, T__f) must remain trait-receiver properties even inside closures (where GROOVY-8049 / 9386 otherwise leave dynamic variables alone), and instance remapped names need the field-helper getter path that static ones already had. isSuperTraitFieldName + collectSuperTraits (including unresolved extends) and the handleUnresolvedProperty instance-field branch with generics correction look careful.
Three-mode tests for static/instance remapped fields, closures, lambdas, and generics are good. CI green.
✅ All tests passed ✅🏷️ Commit: 4c72616 Learn more about TestLens at testlens.app/docs. |
…n a closure or for an instance field (#3136)
|
Merged, potentially with minor changes, as part of #3297. |
…n a closure or for an instance field (#3136)
A sub-trait refers to a public field of a super trait by its remapped name (
T__name, see GROOVY-11641 and GROOVY-11663). Under@TypeCheckedand@CompileStaticthat worked only for a static field outside of closures:Dynamic Groovy runs both. 5.0.8 and 6.0.0 fail the same way.
TraitReceiverTransformerturns a dynamic variable of trait code into a property of the trait receiver, but not inside a closure (GROOVY-8049, GROOVY-9386). It now does so in a closure too when the name is the remapped name of a field of a super trait. The check follows a super trait'sextendsclause when that trait is not transformed yet.TraitTypeCheckingExtension.handleUnresolvedPropertynow resolves the remapped name of an instance field of a super trait through the field helper getter, as it already did for static fields through the static field helper. It does this only on the instance receiver, so an instance field used in a static method is still an error. The type is corrected through the type arguments of the super trait.Tests
TraitASTTransformationTest.testTraitAccessToInheritedStaticFieldInClosure,testTraitAccessToInheritedInstanceField,testTraitAccessToIndirectlyInheritedFieldsandtestTraitAccessToPrecompiledInheritedFieldsrun dynamic,@TypeCheckedand@CompileStatic; their@TypeCheckedand@CompileStaticvariants fail without the change.testTraitAccessToInheritedInstanceFieldInStaticContextchecks that an instance field is still rejected in a static method. Thegroovy.transform.stc,org.codehaus.groovy.classgen.asm.sc,org.codehaus.groovy.transform.traitxandglspackages andgroovy.ThisAndSuperTestpass. The Checkstyle and CodeNarc gates pass.