Skip to content

Commit

Permalink
GROOVY-10633, GROOVY-10662
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 21, 2022
1 parent c09df72 commit 8b3ff02
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5757,7 +5757,8 @@ public void testTypeChecked10624() {
"class A<T> {\n" +
"}\n" +
"class B<T> {\n" +
" B(A<T> a) { }\n" +
" B(A<T> a_of_t) {\n" +
" }\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
Expand All @@ -5770,6 +5771,33 @@ public void testTypeChecked10624() {
runConformTest(sources);
}

@Test
public void testTypeChecked10633() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class A<T, Y> {\n" +
" public B<Y> f\n" +
" A(B<Y> b_of_y, T t) {\n" +
" f = b_of_y\n" +
" }\n" +
"}\n" +
"class B<T> {\n" +
" void m(T t) {\n" +
" }\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"def <T extends Number> void test() {\n" +
" def x = new B<T>()\n" +
" new A<>(x, '').f.m((T) null)\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testTypeChecked10651() {
//@formatter:off
Expand All @@ -5791,4 +5819,29 @@ public void testTypeChecked10651() {

runConformTest(sources);
}

@Test
public void testTypeChecked10662() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class A<X, T> {\n" +
" A(T t, X x) {}\n" +
" void m(X x) {}\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"class B<T extends Number> {\n" +
" void test() {\n" +
" T t = (T) null\n" +
" Character c = 'c'\n" +
" def a = new A<>(c, t)\n" +
" a.m((T) null)\n" + // Cannot find matching method A#m(T)
" }\n" +
"}\n" +
"new B<Integer>().test()\n",
};
//@formatter:on

runConformTest(sources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1765,10 +1765,13 @@ static void applyGenericsConnections(
Map<GenericsTypeName, GenericsType> connections,
Map<GenericsTypeName, GenericsType> resolvedPlaceholders
) {
if (!asBoolean(connections)) return;
/* GRECLIPSE edit -- GROOVY-10662
if (connections == null) return;
int count = 0;
while (count++ < 10000) {
*/
boolean checkForMorePlaceholders = false;
for (Map.Entry<GenericsTypeName, GenericsType> entry : resolvedPlaceholders.entrySet()) {
// entry could be T=T, T=T extends U, T=V, T=String, T=? extends String, etc.
Expand Down Expand Up @@ -1806,11 +1809,13 @@ static void applyGenericsConnections(
}
}
}
/* GRECLIPSE edit
if (!checkForMorePlaceholders) break;
}
if (count >= 10000) {
throw new GroovyBugError("unable to handle generics in " + resolvedPlaceholders + " with connections " + connections);
}
*/
}

private static ClassNode extractType(GenericsType gt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1666,8 +1666,10 @@ public static ClassNode resolveClassNodeGenerics(final Map<GenericsTypeName, Gen

static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> connections, final Map<GenericsTypeName, GenericsType> resolvedPlaceholders) {
if (connections == null || connections.isEmpty()) return;
/* GRECLIPSE edit -- GROOVY-10633, GROOVY-10662
int count = 0;
while (count++ < 10000) {
*/
boolean checkForMorePlaceholders = false;
for (Map.Entry<GenericsTypeName, GenericsType> entry : resolvedPlaceholders.entrySet()) {
// entry could be T=T, T=T extends U, T=V, T=String, T=? extends String, etc.
Expand Down Expand Up @@ -1712,11 +1714,13 @@ static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> c
}
}
}
/* GRECLIPSE edit
if (!checkForMorePlaceholders) break;
}
if (count >= 10000) {
throw new GroovyBugError("unable to handle generics in " + resolvedPlaceholders + " with connections " + connections);
}
*/
}

private static ClassNode extractType(GenericsType gt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1609,9 +1609,11 @@ public static ClassNode resolveClassNodeGenerics(Map<GenericsTypeName, GenericsT

static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> connections, final Map<GenericsTypeName, GenericsType> resolvedPlaceholders) {
if (connections == null || connections.isEmpty()) return;
/* GRECLIPSE edit -- GROOVY-10633, GROOVY-10662
int count = 0;
while (count++ < 10000) {
boolean checkForMorePlaceholders = false;
*/
for (Map.Entry<GenericsTypeName, GenericsType> entry : resolvedPlaceholders.entrySet()) {
// entry could be T=T, T=T extends U, T=V, T=String, T=? extends String, etc.
GenericsType oldValue = entry.getValue();
Expand All @@ -1627,9 +1629,11 @@ static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> c
}
if (newValue == null) {
entry.setValue(newValue = applyGenericsContext(connections, oldValue));
/* GRECLIPSE edit
if (!checkForMorePlaceholders) {
checkForMorePlaceholders = !equalIncludingGenerics(oldValue, newValue);
}
*/
} else if (!newValue.isPlaceholder() || newValue != resolvedPlaceholders.get(name)) {
// GROOVY-6787: Don't override the original if the replacement doesn't respect the bounds otherwise
// the original bounds are lost, which can result in accepting an incompatible type as an argument!
Expand All @@ -1645,18 +1649,22 @@ static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> c
} else {
entry.setValue(newValue);
}
/* GRECLIPSE edit
if (!checkForMorePlaceholders && newValue.isPlaceholder()) {
checkForMorePlaceholders = !equalIncludingGenerics(oldValue, newValue);
}
*/
}
}
}
}
/* GRECLIPSE edit
if (!checkForMorePlaceholders) break;
}
if (count >= 10000) {
throw new GroovyBugError("unable to handle generics in " + resolvedPlaceholders + " with connections " + connections);
}
*/
}

private static ClassNode extractType(GenericsType gt) {
Expand Down

0 comments on commit 8b3ff02

Please sign in to comment.