Skip to content

Commit 76286cf

Browse files
committed
GROOVY-10368
1 parent 9ce3f1d commit 76286cf

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -5138,6 +5138,30 @@ public void testTypeChecked10357() {
51385138
runConformTest(sources, "1");
51395139
}
51405140

5141+
@Test
5142+
public void testTypeChecked10368() {
5143+
for (String bounds : new String[] {"T", "T extends Number", "T extends Object"}) {
5144+
//@formatter:off
5145+
String[] sources = {
5146+
"Main.groovy",
5147+
"class C<" + bounds + "> {\n" +
5148+
" C(p) {\n" +
5149+
" }\n" +
5150+
"}\n" +
5151+
"void m(C<Integer> c) {\n" +
5152+
"}\n" +
5153+
"@groovy.transform.TypeChecked\n" +
5154+
"void test() {\n" +
5155+
" m(new C<>(null))\n" + // Cannot call m(C<java.lang.Integer>) with arguments [C<# extends java.lang.Number>]
5156+
"}\n" +
5157+
"test()\n",
5158+
};
5159+
//@formatter:on
5160+
5161+
runConformTest(sources);
5162+
}
5163+
}
5164+
51415165
@Test
51425166
public void testTypeChecked10414() {
51435167
//@formatter:off

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
12041204
// check if constructor call expression makes use of the diamond operator
12051205
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
12061206
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
1207-
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, et al.
1207+
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, GROOVY-10368, et al.
12081208
if (argumentListExpression.getExpressions().isEmpty()) {
12091209
adjustGenerics(lType, cceType);
12101210
} else {
@@ -1231,8 +1231,8 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
12311231
if (lhs == null || rhs == null || lhs.length != rhs.length) throw new GroovyBugError(
12321232
"Parameterization failed: " + prettyPrintType(pType) + " ~ " + prettyPrintType(type));
12331233

1234-
if (java.util.stream.IntStream.range(0, lhs.length).allMatch(i ->
1235-
GenericsUtils.buildWildcardType(getCombinedBoundType(lhs[i])).isCompatibleWith(getCombinedBoundType(rhs[i])))) {
1234+
if (IntStream.range(0, lhs.length).allMatch(i ->
1235+
GenericsUtils.buildWildcardType(getCombinedBoundType(lhs[i])).isCompatibleWith(rhs[i].getType()))) {
12361236
type = pType; // lType proved to be a viable type witness
12371237
}
12381238
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11271127
ClassNode cceType = cce.getType(), inferredType = lType;
11281128
// check if constructor call expression makes use of the diamond operator
11291129
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
1130-
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, et al.
1130+
/* GRECLIPSE edit -- GROOVY-9948, GROOVY-9983, GROOVY-10291, GROOVY-10368, et al.
11311131
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
11321132
if (argumentListExpression.getExpressions().isEmpty()) {
11331133
adjustGenerics(lType, cceType);
@@ -1156,8 +1156,8 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11561156
if (lhs == null || rhs == null || lhs.length != rhs.length) throw new GroovyBugError(
11571157
"Parameterization failed: " + prettyPrintType(pType) + " ~ " + prettyPrintType(type));
11581158

1159-
if (java.util.stream.IntStream.range(0, lhs.length).allMatch(i ->
1160-
GenericsUtils.buildWildcardType(getCombinedBoundType(lhs[i])).isCompatibleWith(getCombinedBoundType(rhs[i])))) {
1159+
if (IntStream.range(0, lhs.length).allMatch(i ->
1160+
GenericsUtils.buildWildcardType(getCombinedBoundType(lhs[i])).isCompatibleWith(rhs[i].getType()))) {
11611161
type = pType; // lType proved to be a viable type witness
11621162
}
11631163
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11111111
if (!argumentList.getExpressions().isEmpty() && constructor != null) {
11121112
ClassNode type = GenericsUtils.parameterizeType(cceType, cceType);
11131113
type = inferReturnTypeGenerics(type, constructor, argumentList);
1114-
if (type.toString(false).indexOf('#') > 0 // GROOVY-9983, GROOVY-10291
1114+
if (type.toString(false).indexOf('#') > 0 // GROOVY-9983, GROOVY-10291, GROOVY-10368
11151115
// GROOVY-6232, GROOVY-9956: if cce not assignment compatible, process target as additional type witness
11161116
|| checkCompatibleAssignmentTypes(lType, type, cce) && !GenericsUtils.buildWildcardType(lType).isCompatibleWith(type)) {
11171117
// allow covariance of each type parameter, but maintain semantics for nested generics
@@ -1121,8 +1121,8 @@ protected void inferDiamondType(final ConstructorCallExpression cce, final Class
11211121
if (lhs == null || rhs == null || lhs.length != rhs.length) throw new GroovyBugError(
11221122
"Parameterization failed: " + prettyPrintType(pType) + " ~ " + prettyPrintType(type));
11231123

1124-
if (java.util.stream.IntStream.range(0, lhs.length).allMatch(i ->
1125-
GenericsUtils.buildWildcardType(getCombinedBoundType(lhs[i])).isCompatibleWith(getCombinedBoundType(rhs[i])))) {
1124+
if (IntStream.range(0, lhs.length).allMatch(i ->
1125+
GenericsUtils.buildWildcardType(getCombinedBoundType(lhs[i])).isCompatibleWith(rhs[i].getType()))) {
11261126
type = pType; // lType proved to be a viable type witness
11271127
}
11281128
}

0 commit comments

Comments
 (0)