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 7260b060f3 GROOVY-11387: STC: class field or property of map-based type
7260b060f3 is described below
commit 7260b060f335f6a98598f5458f7934d44ea579bc
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 f09578e068..d389568a8a 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1809,7 +1809,7 @@ public class StaticTypeCheckingVisitor extends
ClassCodeVisitorSupport {
&&
Arrays.asList(getTypeCheckingAnnotations()).contains(COMPILESTATIC_CLASSNODE)))
{
return false;
}
- return isOrImplements(receiverType, MAP_TYPE);
+ return isOrImplements(receiverType, MAP_TYPE) &&
!getType(objectExpression).equals(CLASS_Type);
}
/**
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 21988da22c..03da00b322 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -1010,6 +1010,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() {