Skip to content

GROOVY-11694: SC: implicit-this call to static method of super class#2251

Merged
daniellansun merged 1 commit into
masterfrom
GROOVY-11694
Jun 8, 2025
Merged

GROOVY-11694: SC: implicit-this call to static method of super class#2251
daniellansun merged 1 commit into
masterfrom
GROOVY-11694

Conversation

@eric-milles
Copy link
Copy Markdown
Member

StaticMethodCallExpressionTransformer creates "Type.staticMethod(arguments)" and later StaticInvocationWriter gets type of receiver expression as Class<Type>. Use Type for access checks.

@eric-milles eric-milles added the bug label Jun 6, 2025
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 69.0462%. Comparing base (49e1ce3) to head (91cc6d2).
Report is 40 commits behind head on master.

Files with missing lines Patch % Lines
...groovy/classgen/asm/sc/StaticInvocationWriter.java 75.0000% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
...formers/StaticMethodCallExpressionTransformer.java 100.0000% <100.0000%> (ø)
...groovy/classgen/asm/sc/StaticInvocationWriter.java 75.0000% <75.0000%> (+0.1269%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@daniellansun daniellansun requested a review from Copilot June 8, 2025 05:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Copilot AI Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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
}

Copilot uses AI. Check for mistakes.
@daniellansun daniellansun merged commit 40121ec into master Jun 8, 2025
41 checks passed
@daniellansun
Copy link
Copy Markdown
Contributor

Merged. Thanks.

@eric-milles eric-milles deleted the GROOVY-11694 branch June 25, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants