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


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 28c66b486d GROOVY-11370: STC: extension method cannot provide map 
property (pt.2)
28c66b486d is described below

commit 28c66b486d7226781269cee620452c4ba512d7b5
Author: Eric Milles <[email protected]>
AuthorDate: Thu May 23 16:14:42 2024 -0500

    GROOVY-11370: STC: extension method cannot provide map property (pt.2)
---
 .../transform/stc/StaticTypeCheckingVisitor.java      |  6 +++---
 .../transform/stc/FieldsAndPropertiesSTCTest.groovy   | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

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 8da905d8cf..eaad405e67 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1554,6 +1554,8 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
             queue.add(receiverType);
             if (isPrimitiveType(receiverType)) {
                 queue.add(getWrapper(receiverType));
+            } else if (receiverType.isInterface()) {
+                queue.add(OBJECT_TYPE);//GROOVY-5585
             }
             while (!queue.isEmpty()) {
                 ClassNode current = queue.remove();
@@ -3920,9 +3922,7 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                 addBoundType(receiver, owners);
                 addSelfTypes(receiver, owners);
                 addTraitType(receiver, owners);
-                if (receiver.redirect().isInterface()) {
-                    owners.add(Receiver.make(OBJECT_TYPE));
-                } else if (isSuperExpression(objectExpression)) { 
//GROOVY-9909: super.defaultMethod()
+                if (isSuperExpression(objectExpression)) { // GROOVY-9909: 
super.defaultMethod()
                     for (ClassNode in : 
typeCheckingContext.getEnclosingClassNode().getInterfaces()) {
                         if (!receiver.implementsInterface(in)) 
owners.add(Receiver.make(in));
                     }
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy 
b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 665143cef4..4e5c118dba 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -638,6 +638,16 @@ class FieldsAndPropertiesSTCTest extends 
StaticTypeCheckingTestCase {
             def x = list.x
             assert x == [1,2]
         '''
+        assertScript '''
+            void test(List list) {
+                @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                    def type = node.getNodeMetaData(INFERRED_TYPE)
+                    assert type.toString(false) == 'java.lang.Class<? extends 
java.lang.Object>'
+                })
+                def c = list.class
+            }
+            test([])
+        '''
     }
 
     // GROOVY-5700
@@ -938,6 +948,15 @@ class FieldsAndPropertiesSTCTest extends 
StaticTypeCheckingTestCase {
 
     // GROOVY-11370
     void testMapPropertyAccess11() {
+        assertScript '''
+            void test(Map map) { // not LinkedHashMap
+                @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                    assert node.getNodeMetaData(INFERRED_TYPE) == OBJECT_TYPE 
// not METACLASS_TYPE
+                })
+                def val = map.metaClass
+            }
+            test([:])
+        '''
         assertScript '''
             def map = [:]
             @ASTTest(phase=INSTRUCTION_SELECTION, value={

Reply via email to