Skip to content

Commit

Permalink
GROOVY-11370: STC: extension method cannot provide map property (pt.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 23, 2024
1 parent afc9a74 commit 6e2b947
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,8 @@ protected boolean existsProperty(final PropertyExpression pexp, final boolean re
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();
Expand Down Expand Up @@ -3862,9 +3864,7 @@ protected List<Receiver<String>> makeOwnerList(final Expression objectExpression
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));
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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={
Expand Down

0 comments on commit 6e2b947

Please sign in to comment.