Skip to content

Commit 65042d1

Browse files
committed
GROOVY-10225
1 parent d0ef1fa commit 65042d1

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,26 @@ public void testTypeChecked10222a() {
35553555
runConformTest(sources, "works");
35563556
}
35573557

3558+
@Test
3559+
public void testTypeChecked10225() {
3560+
//@formatter:off
3561+
String[] sources = {
3562+
"Main.groovy",
3563+
"def <T> T m(T t) {\n" +
3564+
" print t\n" +
3565+
"}\n" +
3566+
"@groovy.transform.TypeChecked\n" +
3567+
"def <N extends Number, X extends N> void test() {\n" +
3568+
" X x = (X) null\n" +
3569+
" m(false ? x : (X) null)\n" +
3570+
"}\n" +
3571+
"test()\n",
3572+
};
3573+
//@formatter:on
3574+
3575+
runConformTest(sources, "null");
3576+
}
3577+
35583578
@Test
35593579
public void testTypeChecked10235() {
35603580
if (Float.parseFloat(System.getProperty("java.specification.version")) > 8)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6336,7 +6336,7 @@ private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals,
63366336
actuals[i] = getLiteralResultType(pt, at, LINKEDHASHMAP_CLASSNODE);
63376337
} else if (a instanceof ConstructorCallExpression) {
63386338
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
6339-
} else if (a instanceof TernaryExpression && at.isUsingGenerics() && at.getGenericsTypes().length == 0) {
6339+
} else if (a instanceof TernaryExpression && at.getGenericsTypes() != null && at.getGenericsTypes().length == 0) {
63406340
// GROOVY-9983: double diamond scenario -- "m(flag ? new Type<>(...) : new Type<>(...))"
63416341
typeCheckingContext.pushEnclosingBinaryExpression(assignX(varX(p), a, a));
63426342
a.visit(this); // re-visit with target type witness

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5960,7 +5960,7 @@ private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals,
59605960
actuals[i] = getLiteralResultType(pt, at, LINKEDHASHMAP_CLASSNODE);
59615961
} else if (a instanceof ConstructorCallExpression) {
59625962
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
5963-
} else if (a instanceof TernaryExpression && at.isUsingGenerics() && at.getGenericsTypes().length == 0) {
5963+
} else if (a instanceof TernaryExpression && at.getGenericsTypes() != null && at.getGenericsTypes().length == 0) {
59645964
// GROOVY-9983: double diamond scenario -- "m(flag ? new Type<>(...) : new Type<>(...))"
59655965
typeCheckingContext.pushEnclosingBinaryExpression(assignX(varX(p), a, a));
59665966
a.visit(this); // re-visit with target type witness

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5537,7 +5537,7 @@ private void resolvePlaceholdersFromImplicitTypeHints(final ClassNode[] actuals,
55375537
actuals[i] = getLiteralResultType(pt, at, LinkedHashMap_TYPE);
55385538
} else if (a instanceof ConstructorCallExpression) {
55395539
inferDiamondType((ConstructorCallExpression) a, pt); // GROOVY-10086
5540-
} else if (a instanceof TernaryExpression && at.isUsingGenerics() && at.getGenericsTypes().length == 0) {
5540+
} else if (a instanceof TernaryExpression && at.getGenericsTypes() != null && at.getGenericsTypes().length == 0) {
55415541
// GROOVY-9983: double diamond scenario -- "m(flag ? new Type<>(...) : new Type<>(...))"
55425542
typeCheckingContext.pushEnclosingBinaryExpression(assignX(varX(p), a, a));
55435543
a.visit(this); // re-visit with target type witness

0 commit comments

Comments
 (0)