You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/11/23 16:14:49 UTC

[groovy] 02/02: GROOVY-10820: STC: static properties for `Type.name` except from `Class`

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 0a1dc1e3dea2750725ac86bdab4baf184cce640f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Nov 23 09:17:46 2022 -0600

    GROOVY-10820: STC: static properties for `Type.name` except from `Class`
---
 .../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java  | 4 ++++
 .../codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy  | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 7e53d497e3..d35f9967d3 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1627,6 +1627,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                 for (MethodNode method : findDGMMethodsForClassNode(getSourceUnit().getClassLoader(), dgmReceiver, "is" + capName)) {
                     if (isPrimitiveBoolean(method.getReturnType())) methods.add(method);
                 }
+                if (staticOnlyAccess && receiver.getData() == null && !isClassType(receiver.getType())) {
+                    // GROOVY-10820: ensure static extension when property accessed in static manner
+                    methods.removeIf(method -> !((ExtensionMethodNode) method).isStaticExtension());
+                }
                 if (isUsingGenericsOrIsArrayUsingGenerics(dgmReceiver)) {
                     methods.removeIf(method -> // GROOVY-10075: "List<Integer>" vs "List<String>"
                         !typeCheckMethodsWithGenerics(dgmReceiver, ClassNode.EMPTY_ARRAY, method)
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
index 1c26771c7f..e8ca9036f5 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -1519,6 +1519,14 @@ final class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilati
             assert String.metaClass != Class.getMetaClass()
             assert String.getMetaClass() != Class.getMetaClass()
         '''
+        assertScript '''
+            @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                def source = node.rightExpression // "String.metaClass"
+                def target = source.getNodeMetaData(DIRECT_METHOD_CALL_TARGET)
+                assert target.declaringClass == CLASS_Type // not OBJECT_TYPE!
+            })
+            def smc = String.metaClass
+        '''
         assertScript '''
             @ASTTest(phase=INSTRUCTION_SELECTION, value={
                 def source = node.rightExpression // "String.getMetaClass()"