Skip to content

Commit

Permalink
GROOVY-11387: STC: class field or property of map-based type
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 30, 2024
1 parent 3624b9b commit 7260b06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ private boolean isMapProperty(final PropertyExpression pexp, final ClassNode rec
&& Arrays.asList(getTypeCheckingAnnotations()).contains(COMPILESTATIC_CLASSNODE))) {
return false;
}
return isOrImplements(receiverType, MAP_TYPE);
return isOrImplements(receiverType, MAP_TYPE) && !getType(objectExpression).equals(CLASS_Type);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7260b06

Please sign in to comment.