Skip to content

Commit cbfdfe9

Browse files
committed
GROOVY-10229
1 parent 23a8af4 commit cbfdfe9

File tree

5 files changed

+834
-2
lines changed

5 files changed

+834
-2
lines changed

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

+29
Original file line numberDiff line numberDiff line change
@@ -6346,4 +6346,33 @@ public void testCompileStatic10197() {
63466346
runConformTest(sources, "1");
63476347
}
63486348
}
6349+
6350+
@Test
6351+
public void testCompileStatic10229() {
6352+
//@formatter:off
6353+
String[] sources = {
6354+
"Main.groovy",
6355+
"@groovy.transform.CompileStatic\n" +
6356+
"class C {\n" +
6357+
" Map<String,?> a() {\n" +
6358+
" }\n" +
6359+
" Map<String,List<?>> b() {\n" +
6360+
" def c = { ->\n" +
6361+
" [\n" +
6362+
" a(), a()\n" +
6363+
" ]\n" +
6364+
" }\n" +
6365+
" c()\n" +
6366+
" null\n" +
6367+
" }\n" +
6368+
"}\n" +
6369+
"print new C().b()\n",
6370+
};
6371+
//@formatter:on
6372+
6373+
runConformTest(sources, "null");
6374+
6375+
checkDisassemblyFor("C$_b_closure1.class",
6376+
" // Signature: ()Ljava/util/List<Ljava/util/Map<Ljava/lang/String;+Ljava/lang/Object;>;>;\n"); // not L?;
6377+
}
63496378
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/tools/WideningCategories.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,13 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
266266
}
267267
GenericsType[] lubgt = new GenericsType[agt.length];
268268
for (int i = 0; i < agt.length; i++) {
269+
/* GRECLIPSE edit -- GROOVY-10229
269270
ClassNode t1 = agt[i].getType();
270271
ClassNode t2 = bgt[i].getType();
272+
*/
273+
ClassNode t1 = upperBound(agt[i]);
274+
ClassNode t2 = upperBound(bgt[i]);
275+
// GRECLIPSE end
271276
ClassNode basicType;
272277
/* GRECLIPSE edit -- GROOVY-8111
273278
if (areEqualWithGenerics(t1, a) && areEqualWithGenerics(t2,b)) {
@@ -279,7 +284,7 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
279284
} else {
280285
basicType = lowestUpperBound(t1, t2);
281286
}
282-
if (t1.equals(t2)) {
287+
if (t1.equals(t2)/*GRECLIPSE add*/&& !agt[i].isWildcard()/**/) {
283288
lubgt[i] = new GenericsType(basicType);
284289
} else {
285290
lubgt[i] = GenericsUtils.buildWildcardType(basicType);
@@ -290,6 +295,16 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
290295
return plain;
291296
}
292297

298+
// GRECLIPSE add
299+
private static ClassNode upperBound(final GenericsType gt) {
300+
if (gt.isWildcard()) {
301+
ClassNode[] ub = gt.getUpperBounds();
302+
return ub != null ? ub[0] : OBJECT_TYPE;
303+
}
304+
return gt.getType();
305+
}
306+
// GRECLIPSE end
307+
293308
private static ClassNode findGenericsTypeHolderForClass(ClassNode source, ClassNode type) {
294309
if (isPrimitiveType(source)) source = getWrapper(source);
295310
if (source.equals(type)) return source;

base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/tools/WideningCategories.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,21 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
264264
}
265265
GenericsType[] lubgt = new GenericsType[agt.length];
266266
for (int i = 0; i < agt.length; i++) {
267+
/* GRECLIPSE edit -- GROOVY-10229
267268
ClassNode t1 = agt[i].getType();
268269
ClassNode t2 = bgt[i].getType();
270+
*/
271+
ClassNode t1 = upperBound(agt[i]);
272+
ClassNode t2 = upperBound(bgt[i]);
273+
// GRECLIPSE end
269274
ClassNode basicType;
270275
if (areEqualWithGenerics(t1, isPrimitiveType(a)?getWrapper(a):a) && areEqualWithGenerics(t2, isPrimitiveType(b)?getWrapper(b):b)) {
271276
// we are facing a self referencing type !
272277
basicType = fallback;
273278
} else {
274279
basicType = lowestUpperBound(t1, t2);
275280
}
276-
if (t1.equals(t2)) {
281+
if (t1.equals(t2)/*GRECLIPSE add*/&& !agt[i].isWildcard()/**/) {
277282
lubgt[i] = new GenericsType(basicType);
278283
} else {
279284
lubgt[i] = GenericsUtils.buildWildcardType(basicType);
@@ -284,6 +289,16 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
284289
return plain;
285290
}
286291

292+
// GRECLIPSE add
293+
private static ClassNode upperBound(final GenericsType gt) {
294+
if (gt.isWildcard()) {
295+
ClassNode[] ub = gt.getUpperBounds();
296+
return ub != null ? ub[0] : OBJECT_TYPE;
297+
}
298+
return gt.getType();
299+
}
300+
// GRECLIPSE end
301+
287302
private static ClassNode findGenericsTypeHolderForClass(ClassNode source, ClassNode type) {
288303
if (isPrimitiveType(source)) source = getWrapper(source);
289304
if (source.equals(type)) return source;

base/org.codehaus.groovy40/.checkstyle

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<file-match-pattern match-pattern="groovy/ast/expr/RangeExpression.java" include-pattern="false" />
3636
<file-match-pattern match-pattern="groovy/ast/expr/(Static)?MethodCallExpression.java" include-pattern="false" />
3737
<file-match-pattern match-pattern="groovy/ast/tools/(Expression|Generics)Utils.java" include-pattern="false" />
38+
<file-match-pattern match-pattern="groovy/ast/tools/WideningCategories.java" include-pattern="false" />
3839
<file-match-pattern match-pattern="groovy/classgen/(Annotation|Enum|VariableScope)Visitor.java" include-pattern="false" />
3940
<file-match-pattern match-pattern="groovy/classgen/(Extended)?Verifier.java" include-pattern="false" />
4041
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticInvocationWriter.java" include-pattern="false" />

0 commit comments

Comments
 (0)