Skip to content

Commit 01a76c6

Browse files
committed
GROOVY-9821
1 parent 789df42 commit 01a76c6

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+23
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,29 @@ public void testTypeChecked9803() {
493493
runConformTest(sources, "123");
494494
}
495495

496+
@Test
497+
public void testTypeChecked9821() {
498+
//@formatter:off
499+
String[] sources = {
500+
"Main.groovy",
501+
"@groovy.transform.TypeChecked\n" +
502+
"def test(A a) {\n" +
503+
" a.bees*.c\n" +
504+
"}\n",
505+
506+
"Types.java",
507+
"interface A {\n" +
508+
" java.util.Collection<? extends B> getBees();\n" +
509+
"}\n" +
510+
"interface B {\n" +
511+
" Object getC();\n" +
512+
"}\n",
513+
};
514+
//@formatter:on
515+
516+
runNegativeTest(sources, "");
517+
}
518+
496519
@Test
497520
public void testTypeChecked9822() {
498521
//@formatter:off

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,8 @@ static ClassNode applyGenericsContext(final Map<GenericsTypeName, GenericsType>
20412041
return newBound;
20422042
}
20432043

2044-
private static ClassNode getCombinedBoundType(GenericsType genericsType) {
2044+
// GRECLIPSE private->package
2045+
static ClassNode getCombinedBoundType(GenericsType genericsType) {
20452046
//TODO: this method should really return some kind of meta ClassNode
20462047
// representing the combination of all bounds. The code here, just picks
20472048
// something out to be able to proceed and is not actually correct

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+5
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters;
243243
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable;
244244
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.fullyResolveType;
245+
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCombinedBoundType;
245246
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getGenericsWithoutArray;
246247
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getOperationName;
247248
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf;
@@ -1757,8 +1758,12 @@ private ClassNode getTypeForSpreadExpression(ClassNode testClass, ClassNode obje
17571758
ClassNode callType = getType(mce);
17581759
if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null;
17591760
GenericsType[] types = callType.getGenericsTypes();
1761+
/* GRECLIPSE edit -- GROOVY-9821
17601762
ClassNode contentType = OBJECT_TYPE;
17611763
if (types != null && types.length == 1) contentType = types[0].getType();
1764+
*/
1765+
ClassNode contentType = (types != null && types.length == 1 ? getCombinedBoundType(types[0]) : OBJECT_TYPE);
1766+
// GRECLIPSE end
17621767
PropertyExpression subExp = new PropertyExpression(varX("{}", contentType), pexp.getPropertyAsString());
17631768
AtomicReference<ClassNode> result = new AtomicReference<ClassNode>();
17641769
if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) {

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,8 @@ static ClassNode applyGenericsContext(final Map<GenericsTypeName, GenericsType>
19201920
return newBound;
19211921
}
19221922

1923-
private static ClassNode getCombinedBoundType(final GenericsType genericsType) {
1923+
// GRECLIPSE private->package
1924+
static ClassNode getCombinedBoundType(final GenericsType genericsType) {
19241925
// TODO: this method should really return some kind of meta ClassNode
19251926
// representing the combination of all bounds. The code here, just picks
19261927
// something out to be able to proceed and is not actually correct

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+5
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters;
247247
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable;
248248
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.fullyResolveType;
249+
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCombinedBoundType;
249250
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getCorrectedClassNode;
250251
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getGenericsWithoutArray;
251252
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getOperationName;
@@ -1694,8 +1695,12 @@ private ClassNode getTypeForSpreadExpression(final ClassNode testClass, final Cl
16941695
ClassNode callType = getType(mce);
16951696
if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null;
16961697
GenericsType[] types = callType.getGenericsTypes();
1698+
/* GRECLIPSE edit -- GROOVY-9821
16971699
ClassNode contentType = OBJECT_TYPE;
16981700
if (types != null && types.length == 1) contentType = types[0].getType();
1701+
*/
1702+
ClassNode contentType = (types != null && types.length == 1 ? getCombinedBoundType(types[0]) : OBJECT_TYPE);
1703+
// GRECLIPSE end
16991704
PropertyExpression subExp = new PropertyExpression(varX("{}", contentType), pexp.getPropertyAsString());
17001705
AtomicReference<ClassNode> result = new AtomicReference<>();
17011706
if (existsProperty(subExp, true, new PropertyLookupVisitor(result))) {

0 commit comments

Comments
 (0)