Skip to content

Commit

Permalink
GROOVY-11387: STC: entry before field for outside map property reference
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 24, 2024
1 parent 7d01a83 commit febdbdd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,8 @@ private boolean isMapProperty(final PropertyExpression pexp, final ClassNode rec
&& Arrays.asList(getTypeCheckingAnnotations()).contains(COMPILESTATIC_CLASSNODE))) {
return false;
}
return isOrImplements(receiverType, MAP_TYPE) && !getType(objectExpression).equals(CLASS_Type);
return isOrImplements(receiverType, MAP_TYPE) && (!getType(objectExpression).equals(CLASS_Type)
|| (pexp.isImplicitThis() && isThisExpression(objectExpression) && typeCheckingContext.getEnclosingClosure() != null));
}

/**
Expand Down
12 changes: 12 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,18 @@ class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
assert xxx == null
assert yyy == null
'''
assertScript '''
static void test() {
def map = new HashMap<String,String>()
map.with{
@ASTTest(phase=INSTRUCTION_SELECTION, value={
assert node.getNodeMetaData(INFERRED_TYPE) == STRING_TYPE
})
def xxx = table
}
}
test()
'''
assertScript '''
class HttpHeaders extends HashMap<String,List<String>> {
public static final String ACCEPT = 'Accept'
Expand Down

0 comments on commit febdbdd

Please sign in to comment.