Skip to content

Commit

Permalink
GROOVY-10229
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 14, 2021
1 parent 23a8af4 commit cbfdfe9
Show file tree
Hide file tree
Showing 5 changed files with 834 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6346,4 +6346,33 @@ public void testCompileStatic10197() {
runConformTest(sources, "1");
}
}

@Test
public void testCompileStatic10229() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C {\n" +
" Map<String,?> a() {\n" +
" }\n" +
" Map<String,List<?>> b() {\n" +
" def c = { ->\n" +
" [\n" +
" a(), a()\n" +
" ]\n" +
" }\n" +
" c()\n" +
" null\n" +
" }\n" +
"}\n" +
"print new C().b()\n",
};
//@formatter:on

runConformTest(sources, "null");

checkDisassemblyFor("C$_b_closure1.class",
" // Signature: ()Ljava/util/List<Ljava/util/Map<Ljava/lang/String;+Ljava/lang/Object;>;>;\n"); // not L?;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,13 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
}
GenericsType[] lubgt = new GenericsType[agt.length];
for (int i = 0; i < agt.length; i++) {
/* GRECLIPSE edit -- GROOVY-10229
ClassNode t1 = agt[i].getType();
ClassNode t2 = bgt[i].getType();
*/
ClassNode t1 = upperBound(agt[i]);
ClassNode t2 = upperBound(bgt[i]);
// GRECLIPSE end
ClassNode basicType;
/* GRECLIPSE edit -- GROOVY-8111
if (areEqualWithGenerics(t1, a) && areEqualWithGenerics(t2,b)) {
Expand All @@ -279,7 +284,7 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
} else {
basicType = lowestUpperBound(t1, t2);
}
if (t1.equals(t2)) {
if (t1.equals(t2)/*GRECLIPSE add*/&& !agt[i].isWildcard()/**/) {
lubgt[i] = new GenericsType(basicType);
} else {
lubgt[i] = GenericsUtils.buildWildcardType(basicType);
Expand All @@ -290,6 +295,16 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
return plain;
}

// GRECLIPSE add
private static ClassNode upperBound(final GenericsType gt) {
if (gt.isWildcard()) {
ClassNode[] ub = gt.getUpperBounds();
return ub != null ? ub[0] : OBJECT_TYPE;
}
return gt.getType();
}
// GRECLIPSE end

private static ClassNode findGenericsTypeHolderForClass(ClassNode source, ClassNode type) {
if (isPrimitiveType(source)) source = getWrapper(source);
if (source.equals(type)) return source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,21 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
}
GenericsType[] lubgt = new GenericsType[agt.length];
for (int i = 0; i < agt.length; i++) {
/* GRECLIPSE edit -- GROOVY-10229
ClassNode t1 = agt[i].getType();
ClassNode t2 = bgt[i].getType();
*/
ClassNode t1 = upperBound(agt[i]);
ClassNode t2 = upperBound(bgt[i]);
// GRECLIPSE end
ClassNode basicType;
if (areEqualWithGenerics(t1, isPrimitiveType(a)?getWrapper(a):a) && areEqualWithGenerics(t2, isPrimitiveType(b)?getWrapper(b):b)) {
// we are facing a self referencing type !
basicType = fallback;
} else {
basicType = lowestUpperBound(t1, t2);
}
if (t1.equals(t2)) {
if (t1.equals(t2)/*GRECLIPSE add*/&& !agt[i].isWildcard()/**/) {
lubgt[i] = new GenericsType(basicType);
} else {
lubgt[i] = GenericsUtils.buildWildcardType(basicType);
Expand All @@ -284,6 +289,16 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
return plain;
}

// GRECLIPSE add
private static ClassNode upperBound(final GenericsType gt) {
if (gt.isWildcard()) {
ClassNode[] ub = gt.getUpperBounds();
return ub != null ? ub[0] : OBJECT_TYPE;
}
return gt.getType();
}
// GRECLIPSE end

private static ClassNode findGenericsTypeHolderForClass(ClassNode source, ClassNode type) {
if (isPrimitiveType(source)) source = getWrapper(source);
if (source.equals(type)) return source;
Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy40/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<file-match-pattern match-pattern="groovy/ast/expr/RangeExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/expr/(Static)?MethodCallExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/tools/(Expression|Generics)Utils.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/tools/WideningCategories.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/(Annotation|Enum|VariableScope)Visitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/(Extended)?Verifier.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticInvocationWriter.java" include-pattern="false" />
Expand Down
Loading

0 comments on commit cbfdfe9

Please sign in to comment.