Skip to content

Commit c5ca6a4

Browse files
committed
GROOVY-8111
1 parent ac06026 commit c5ca6a4

File tree

5 files changed

+810
-1
lines changed

5 files changed

+810
-1
lines changed

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

+33-1
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,38 @@ public void testTypeChecked8103() {
901901
runNegativeTest(sources, "");
902902
}
903903

904+
@Test
905+
public void testTypeChecked8111() {
906+
//@formatter:off
907+
String[] sources = {
908+
"Main.groovy",
909+
"@groovy.transform.TypeChecked\n" +
910+
"def test(thing) {\n" +
911+
" thing != null ?: Pair.of('k','v')\n" + // StackOverflowError
912+
"}\n",
913+
914+
"Pair.groovy",
915+
"class Pair<L,R> implements Map.Entry<L,R>, Comparable<Pair<L,R>>, Serializable {\n" +
916+
" public final L left\n" +
917+
" public final R right\n" +
918+
" private Pair(final L left, final R right) {\n" +
919+
" this.left = left\n" +
920+
" this.right = right\n" +
921+
" }\n" +
922+
" static <L, R> Pair<L, R> of(final L left, final R right) {\n" +
923+
" return new Pair<>(left, right)\n" +
924+
" }\n" +
925+
" L getKey() { left }\n" +
926+
" R getValue() { right }\n" +
927+
" R setValue(R value) { right }\n" +
928+
" int compareTo(Pair<L,R> that) { 0 }\n" +
929+
"}\n",
930+
};
931+
//@formatter:on
932+
933+
runConformTest(sources);
934+
}
935+
904936
@Test
905937
public void testTypeChecked8202() {
906938
//@formatter:off
@@ -2940,7 +2972,7 @@ public void testTypeChecked10111a() {
29402972
" new String[]{ 1, (long)2, (short)3 }\n" +
29412973
"}\n" +
29422974
"def result = test()\n" +
2943-
"assert result.toString == '[1, 2, 3]'\n" +
2975+
"assert result.toString() == '[1, 2, 3]'\n" +
29442976
"assert result.every { it.class == String }\n",
29452977
};
29462978
//@formatter:on

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

+6
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
269269
ClassNode t1 = agt[i].getType();
270270
ClassNode t2 = bgt[i].getType();
271271
ClassNode basicType;
272+
/* GRECLIPSE edit -- GROOVY-8111
272273
if (areEqualWithGenerics(t1, a) && areEqualWithGenerics(t2,b)) {
274+
*/
275+
if (areEqualWithGenerics(t1, isPrimitiveType(a)?getWrapper(a):a) && areEqualWithGenerics(t2, isPrimitiveType(b)?getWrapper(b):b)) {
276+
// GRECLIPSE end
273277
// we are facing a self referencing type !
274278
basicType = fallback;
275279
} else {
@@ -722,7 +726,9 @@ private static boolean areEqualWithGenerics(ClassNode a, ClassNode b) {
722726
GenericsType ga = gta[i];
723727
GenericsType gb = gtb[i];
724728
boolean result = ga.isPlaceholder()==gb.isPlaceholder() && ga.isWildcard()==gb.isWildcard();
729+
/* GRECLIPSE edit -- GROOVY-8111
725730
result = result && ga.isResolved() && gb.isResolved();
731+
*/
726732
result = result && ga.getName().equals(gb.getName());
727733
result = result && areEqualWithGenerics(ga.getType(), gb.getType());
728734
result = result && areEqualWithGenerics(ga.getLowerBound(), gb.getLowerBound());

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

+6
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ private static ClassNode parameterizeLowestUpperBound(final ClassNode lub, final
267267
ClassNode t1 = agt[i].getType();
268268
ClassNode t2 = bgt[i].getType();
269269
ClassNode basicType;
270+
/* GRECLIPSE edit -- GROOVY-8111
270271
if (areEqualWithGenerics(t1, a) && areEqualWithGenerics(t2,b)) {
272+
*/
273+
if (areEqualWithGenerics(t1, isPrimitiveType(a)?getWrapper(a):a) && areEqualWithGenerics(t2, isPrimitiveType(b)?getWrapper(b):b)) {
274+
// GRECLIPSE end
271275
// we are facing a self referencing type !
272276
basicType = fallback;
273277
} else {
@@ -718,7 +722,9 @@ private static boolean areEqualWithGenerics(ClassNode a, ClassNode b) {
718722
GenericsType ga = gta[i];
719723
GenericsType gb = gtb[i];
720724
boolean result = ga.isPlaceholder()==gb.isPlaceholder() && ga.isWildcard()==gb.isWildcard();
725+
/* GRECLIPSE edit -- GROOVY-8111
721726
result = result && ga.isResolved() && gb.isResolved();
727+
*/
722728
result = result && ga.getName().equals(gb.getName());
723729
result = result && areEqualWithGenerics(ga.getType(), gb.getType());
724730
result = result && areEqualWithGenerics(ga.getLowerBound(), gb.getLowerBound());

base/org.codehaus.groovy40/.checkstyle

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

0 commit comments

Comments
 (0)