Skip to content

Commit 200038a

Browse files
committed
GROOVY-10847
1 parent d6219e8 commit 200038a

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6677,4 +6677,26 @@ public void testTypeChecked10846() {
66776677

66786678
runConformTest(sources);
66796679
}
6680+
6681+
@Test
6682+
public void testTypeChecked10847() {
6683+
//@formatter:off
6684+
String[] sources = {
6685+
"Main.groovy",
6686+
"class A<T, U> {\n" +
6687+
"}\n" +
6688+
"class B {\n" +
6689+
" def <X extends A<Character, Boolean>, Y extends X> void m(X x, Y y) {\n" +
6690+
" }\n" +
6691+
"}\n" +
6692+
"@groovy.transform.TypeChecked\n" +
6693+
"test() {\n" +
6694+
" new B().m(null, new A<>())\n" +
6695+
"}\n" +
6696+
"test()\n",
6697+
};
6698+
//@formatter:on
6699+
6700+
runConformTest(sources);
6701+
}
66806702
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,10 @@ && checkCompatibleAssignmentTypes(lType, type, cce) && !GenericsUtils.buildWildc
11601160
}
11611161
inferredType = type;
11621162
}
1163-
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
1163+
// GROOVY-10344, GROOVY-10847: "T t = new C<>()" where "T" may extend another type parameter
1164+
while (inferredType.isGenericsPlaceHolder() && asBoolean(inferredType.getGenericsTypes())) {
11641165
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);
1165-
1166+
}
11661167
adjustGenerics(inferredType, cceType);
11671168
storeType(cce, cceType);
11681169
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,10 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11191119
}
11201120
inferredType = type;
11211121
}
1122-
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
1122+
// GROOVY-10344, GROOVY-10847: "T t = new C<>()" where "T" may extend another type parameter
1123+
while (inferredType.isGenericsPlaceHolder() && asBoolean(inferredType.getGenericsTypes())) {
11231124
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);
1124-
1125+
}
11251126
adjustGenerics(inferredType, cceType);
11261127
storeType(cce, cceType);
11271128
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,10 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11231123
}
11241124
inferredType = type;
11251125
}
1126-
if (inferredType.isGenericsPlaceHolder()) // GROOVY-10344: "T t = new C<>()"
1126+
// GROOVY-10344, GROOVY-10847: "T t = new C<>()" where "T" may extend another type parameter
1127+
while (inferredType.isGenericsPlaceHolder() && asBoolean(inferredType.getGenericsTypes())) {
11271128
inferredType = getCombinedBoundType(inferredType.getGenericsTypes()[0]);
1128-
1129+
}
11291130
adjustGenerics(inferredType, cceType);
11301131
storeType(cce, cceType);
11311132
}

0 commit comments

Comments
 (0)