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 8056ee85d6 GROOVY-11387: STC: entry before field for outside map
property reference
8056ee85d6 is described below
commit 8056ee85d6e4a2d7e8d33a4596432f398cd75fb1
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 101950d859..acd1a7af9f 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1850,7 +1850,8 @@ public class StaticTypeCheckingVisitor extends
ClassCodeVisitorSupport {
&&
Arrays.asList(getTypeCheckingAnnotations()).contains(COMPILESTATIC_CLASSNODE)) {
return false;
}
- return isOrImplements(receiverType, MAP_TYPE) &&
!isClassType(getType(objectExpression));
+ return isOrImplements(receiverType, MAP_TYPE) &&
(!isClassType(getType(objectExpression))
+ || (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 977e728e6d..a560e6e9c4 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -1013,6 +1013,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'