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

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


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new febdbdd9c1 GROOVY-11387: STC: entry before field for outside map 
property reference
febdbdd9c1 is described below

commit febdbdd9c18f89f379e1da9cad6fe5281425d4e3
Author: Eric Milles <[email protected]>
AuthorDate: Mon Jun 24 14:23:44 2024 -0500

    GROOVY-11387: STC: entry before field for outside map property reference
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java      |  3 ++-
 .../groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy   | 12 ++++++++++++
 2 files changed, 14 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 13b2ef33f4..a2e261d0f6 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1814,7 +1814,8 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                 && 
Arrays.asList(getTypeCheckingAnnotations()).contains(COMPILESTATIC_CLASSNODE))) 
{
             return false;
         }
-        return isOrImplements(receiverType, MAP_TYPE) && 
!getType(objectExpression).equals(CLASS_Type);
+        return isOrImplements(receiverType, MAP_TYPE) && 
(!getType(objectExpression).equals(CLASS_Type)
+            || (pexp.isImplicitThis() && isThisExpression(objectExpression) && 
typeCheckingContext.getEnclosingClosure() != null));
     }
 
     /**
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy 
b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 89890ba684..068b0bef2e 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -1010,6 +1010,18 @@ class FieldsAndPropertiesSTCTest extends 
StaticTypeCheckingTestCase {
             assert xxx == null
             assert yyy == null
         '''
+        assertScript '''
+            static void test() {
+                def map = new HashMap<String,String>()
+                map.with{
+                    @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                        assert node.getNodeMetaData(INFERRED_TYPE) == 
STRING_TYPE
+                    })
+                    def xxx = table
+                }
+            }
+            test()
+        '''
         assertScript '''
             class HttpHeaders extends HashMap<String,List<String>> {
                 public static final String ACCEPT = 'Accept'

Reply via email to