Skip to content

Commit

Permalink
GROOVY-10330
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 30, 2021
1 parent bbf178a commit 0a77b5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4294,4 +4294,29 @@ public void testTypeChecked10327() {

runConformTest(sources);
}

@Test
public void testTypeChecked10330() {
if (Float.parseFloat(System.getProperty("java.specification.version")) > 8)
vmArguments = new String[] {"--add-opens", "java.base/java.util.function=ALL-UNNAMED"};

//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TypeChecked\n" +
"class C<T> {\n" +
" T y\n" +
" void m(T x, java.util.function.Function<T, T> f) {\n" +
" print f.apply(x)\n" +
" }\n" +
" void test(T x, java.util.function.Function<T, T> f) {\n" +
" m(true ? x : y, f)\n" +
" }\n" +
"}\n" +
"new C<String>().test('WORKS', { it.toLowerCase() })\n",
};
//@formatter:on

runConformTest(sources, "works");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public static ClassNode lowestUpperBound(List<ClassNode> nodes) {
public static ClassNode lowestUpperBound(ClassNode a, ClassNode b) {
ClassNode lub = lowestUpperBound(a, b, null, null);
if (lub==null || !lub.isUsingGenerics()) return lub;
// GRECLIPSE add -- GROOVY-10130
if (lub.isGenericsPlaceHolder()) return lub;
// GRECLIPSE end
// types may be parameterized. If so, we must ensure that generic type arguments
// are made compatible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ public static ClassNode lowestUpperBound(List<ClassNode> nodes) {
public static ClassNode lowestUpperBound(ClassNode a, ClassNode b) {
ClassNode lub = lowestUpperBound(a, b, null, null);
if (lub==null || !lub.isUsingGenerics()) return lub;
// GRECLIPSE add -- GROOVY-10130
if (lub.isGenericsPlaceHolder()) return lub;
// GRECLIPSE end
// types may be parameterized. If so, we must ensure that generic type arguments
// are made compatible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ public static ClassNode lowestUpperBound(final List<ClassNode> nodes) {
*/
public static ClassNode lowestUpperBound(final ClassNode a, final ClassNode b) {
ClassNode lub = lowestUpperBound(a, b, null, null);
if (lub==null || !lub.isUsingGenerics()) return lub;
// types may be parameterized. If so, we must ensure that generic type arguments
if (lub == null || !lub.isUsingGenerics()
|| lub.isGenericsPlaceHolder()) { // GROOVY-10330
return lub;
}
// types may be parameterized; if so, ensure that generic type arguments
// are made compatible

if (lub instanceof LowestUpperBoundClassNode) {
// no parent super class representing both types could be found
// or both class nodes implement common interfaces which may have
Expand Down

0 comments on commit 0a77b5e

Please sign in to comment.