Skip to content

Commit

Permalink
GROOVY-11401: STC: don't continue member search after map-based receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 10, 2024
1 parent da99cd9 commit 24328d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,10 @@ else if (field != null && enclosingTypes.contains(current) && storeField(field,
foundGetterOrSetter = (foundGetterOrSetter || getter != null || !setters.isEmpty());
}

if (readMode && !isMapProperty(pexp, receiverType)) { // GROOVY-11369, GROOVY-11370, GROOVY-11372
// GROOVY-11369, GROOVY-11370, GROOVY-11372, GROOVY-11401: map entry
if (isMapProperty(pexp, receiverType)) break;

if (readMode) {
// GROOVY-5568, GROOVY-9115, GROOVY-9123: the property may be provided by an extension method
for (ClassNode dgmReceiver : isPrimitiveType(receiverType) ? new ClassNode[]{receiverType, getWrapper(receiverType)} : new ClassNode[]{receiverType}) {
Set<MethodNode> methods = findDGMMethodsForClassNode(getSourceUnit().getClassLoader(), dgmReceiver, getterName);
Expand Down Expand Up @@ -1669,7 +1672,7 @@ else if (field != null && enclosingTypes.contains(current) && storeField(field,
}
}

// GROOVY-7996: check if receiver implements get(String)/set(String,Object) or propertyMissing(String) or $static_propertyMissing(String)?
// GROOVY-7996: check if receiver implements get(String)/set(String,Object) or propertyMissing(String)
if (!receiverType.isArray() && !isPrimitiveType(getUnwrapper(receiverType))
&& pexp.isImplicitThis() && typeCheckingContext.getEnclosingClosure() != null) {
MethodNode mopMethod;
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 @@ -1037,6 +1037,25 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
'''
}

// GROOVY-11401
void testMapPropertyAccess13() {
assertScript '''
class C {
private Object obj = 'field'
def m() {
Map<String,String> map = [:].withDefault{'entry'}
map.with {
@ASTTest(phase=INSTRUCTION_SELECTION, value={
assert node.getNodeMetaData(INFERRED_TYPE) == STRING_TYPE
})
def xxx = obj
}
}
}
assert new C().m() == 'entry'
'''
}

void testTypeCheckerDoesNotThinkPropertyIsReadOnly() {
assertScript '''
// a base class defining a read-only property
Expand Down

0 comments on commit 24328d6

Please sign in to comment.