GROOVY-11694: SC: implicit-this call to static method of super class#2251
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2251 +/- ##
==================================================
+ Coverage 69.0411% 69.0462% +0.0051%
- Complexity 29711 29715 +4
==================================================
Files 1423 1423
Lines 114413 114419 +6
Branches 19844 19845 +1
==================================================
+ Hits 78992 79002 +10
Misses 28786 28786
+ Partials 6635 6631 -4
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This pull request addresses GROOVY-11694 by correcting how implicit-this calls to static methods of a super class are handled and updating type usage to ensure proper access checks.
- Added new tests to verify static method calls through instance and inheritance scenarios.
- Updated StaticMethodCallExpressionTransformer.java to propagate source position information on receiver expressions.
- Modified StaticInvocationWriter.java to unwrap class nodes and replace deprecated helper methods.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/test/groovy/groovy/transform/stc/MethodCallsSTCTest.groovy | Added and renamed tests to cover new scenarios related to implicit-this static calls. |
| src/main/java/org/codehaus/groovy/transform/sc/transformers/StaticMethodCallExpressionTransformer.java | Updated receiver initialization with proper source position settings using var. |
| src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java | Refactored type checks and receiver type unwrapping to support GROOVY-11694. |
Comments suppressed due to low confidence (1)
src/test/groovy/groovy/transform/stc/MethodCallsSTCTest.groovy:122
- [nitpick] The renamed test method 'testStaticMethodCallWithInheritance2' could be more descriptive to clearly differentiate its purpose from 'testStaticMethodCallThroughInstance'. Consider a name that reflects the specifics of the inheritance and static access scenario being validated.
// GROOVY-11694
|
|
||
| ClassNode receiverType = receiver == null ? ClassHelper.OBJECT_TYPE : controller.getTypeChooser().resolveType(receiver, controller.getThisType()); | ||
| if (StaticTypeCheckingSupport.isClassClassNodeWrappingConcreteType(receiverType) && !ClassHelper.isClassType(declaringClass)) { | ||
| receiverType = receiverType.getGenericsTypes()[0].getType(); // GROOVY-11694 |
There was a problem hiding this comment.
Consider adding a check to ensure that receiverType.getGenericsTypes() is not null and contains at least one element before accessing index 0 to prevent potential NullPointerExceptions.
| receiverType = receiverType.getGenericsTypes()[0].getType(); // GROOVY-11694 | |
| if (receiverType.getGenericsTypes() != null && receiverType.getGenericsTypes().length > 0) { | |
| receiverType = receiverType.getGenericsTypes()[0].getType(); // GROOVY-11694 | |
| } else { | |
| // Handle the case where generics types are null or empty | |
| receiverType = ClassHelper.OBJECT_TYPE; // Default to Object type | |
| } |
|
Merged. Thanks. |
StaticMethodCallExpressionTransformercreates "Type.staticMethod(arguments)" and laterStaticInvocationWritergets type of receiver expression asClass<Type>. UseTypefor access checks.