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 6e2b9471bc GROOVY-11370: STC: extension method cannot provide map
property (pt.2)
6e2b9471bc is described below
commit 6e2b9471bc2092c4746677f22bc87eda70cbb253
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 12b8547410..bf9d94ee49 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1539,6 +1539,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();
@@ -3862,9 +3864,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 3f7fa12202..9da6508290 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -644,6 +644,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
@@ -935,6 +945,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={