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 ac4e5e1902 GROOVY-11387: STC: class field or property of map-based type
ac4e5e1902 is described below

commit ac4e5e1902d95d83e2e447f677f32282fb0889b0
Author: Eric Milles <[email protected]>
AuthorDate: Thu May 30 14:47:44 2024 -0500

    GROOVY-11387: STC: class field or property of map-based type
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java        |  2 +-
 .../groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy     | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

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 6a0e82ae63..d5663a340d 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1846,7 +1846,7 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                 && 
Arrays.asList(getTypeCheckingAnnotations()).contains(COMPILESTATIC_CLASSNODE)) {
             return false;
         }
-        return isOrImplements(receiverType, MAP_TYPE);
+        return isOrImplements(receiverType, MAP_TYPE) && 
!isClassType(getType(objectExpression));
     }
 
     /**
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy 
b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index efb3a90763..d35b8777e2 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -1013,6 +1013,16 @@ class FieldsAndPropertiesSTCTest extends 
StaticTypeCheckingTestCase {
             assert xxx == null
             assert yyy == null
         '''
+        assertScript '''
+            class HttpHeaders extends HashMap<String,List<String>> {
+                public static final String ACCEPT = 'Accept'
+            }
+            @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                assert node.getNodeMetaData(INFERRED_TYPE) == STRING_TYPE
+            })
+            def accept = HttpHeaders.ACCEPT
+            assert accept == 'Accept'
+        '''
     }
 
     void testTypeCheckerDoesNotThinkPropertyIsReadOnly() {

Reply via email to