Skip to content

Commit

Permalink
GROOVY-9821
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 19, 2020
1 parent 789df42 commit 01a76c6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,29 @@ public void testTypeChecked9803() {
runConformTest(sources, "123");
}

@Test
public void testTypeChecked9821() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TypeChecked\n" +
"def test(A a) {\n" +
" a.bees*.c\n" +
"}\n",

"Types.java",
"interface A {\n" +
" java.util.Collection<? extends B> getBees();\n" +
"}\n" +
"interface B {\n" +
" Object getC();\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources, "");
}

@Test
public void testTypeChecked9822() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,8 @@ static ClassNode applyGenericsContext(final Map<GenericsTypeName, GenericsType>
return newBound;
}

private static ClassNode getCombinedBoundType(GenericsType genericsType) {
// GRECLIPSE private->package
static ClassNode getCombinedBoundType(GenericsType genericsType) {
//TODO: this method should really return some kind of meta ClassNode
// representing the combination of all bounds. The code here, just picks
// something out to be able to proceed and is not actually correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.fullyResolveType;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCombinedBoundType;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getGenericsWithoutArray;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getOperationName;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf;
Expand Down Expand Up @@ -1757,8 +1758,12 @@ private ClassNode getTypeForSpreadExpression(ClassNode testClass, ClassNode obje
ClassNode callType = getType(mce);
if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null;
GenericsType[] types = callType.getGenericsTypes();
/* GRECLIPSE edit -- GROOVY-9821
ClassNode contentType = OBJECT_TYPE;
if (types != null && types.length == 1) contentType = types[0].getType();
*/
ClassNode contentType = (types != null && types.length == 1 ? getCombinedBoundType(types[0]) : OBJECT_TYPE);
// GRECLIPSE end
PropertyExpression subExp = new PropertyExpression(varX("{}", contentType), pexp.getPropertyAsString());
AtomicReference<ClassNode> result = new AtomicReference<ClassNode>();
if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,8 @@ static ClassNode applyGenericsContext(final Map<GenericsTypeName, GenericsType>
return newBound;
}

private static ClassNode getCombinedBoundType(final GenericsType genericsType) {
// GRECLIPSE private->package
static ClassNode getCombinedBoundType(final GenericsType genericsType) {
// TODO: this method should really return some kind of meta ClassNode
// representing the combination of all bounds. The code here, just picks
// something out to be able to proceed and is not actually correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.fullyResolveType;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCombinedBoundType;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCorrectedClassNode;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getGenericsWithoutArray;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getOperationName;
Expand Down Expand Up @@ -1694,8 +1695,12 @@ private ClassNode getTypeForSpreadExpression(final ClassNode testClass, final Cl
ClassNode callType = getType(mce);
if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null;
GenericsType[] types = callType.getGenericsTypes();
/* GRECLIPSE edit -- GROOVY-9821
ClassNode contentType = OBJECT_TYPE;
if (types != null && types.length == 1) contentType = types[0].getType();
*/
ClassNode contentType = (types != null && types.length == 1 ? getCombinedBoundType(types[0]) : OBJECT_TYPE);
// GRECLIPSE end
PropertyExpression subExp = new PropertyExpression(varX("{}", contentType), pexp.getPropertyAsString());
AtomicReference<ClassNode> result = new AtomicReference<>();
if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) {
Expand Down

0 comments on commit 01a76c6

Please sign in to comment.