Skip to content

Commit

Permalink
another test to challenge nested generics with raw type within
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-herrmann committed Jun 6, 2024
1 parent ac55ce0 commit 5903df9
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3725,6 +3725,58 @@ The method bar() is undefined for the type Object
runner.runNegativeTest();
}

public void testGH2470_generic2() {
if (this.complianceLevel < ClassFileConstants.JDK1_8) return;
Runner runner = new Runner();
runner.customOptions = getCompilerOptions();
runner.customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
runner.testFiles = new String[] {
"X.java",
"""
import java.util.List;
import java.util.function.Supplier;
interface XListSupplier extends Supplier<List<X>> {}
interface XList extends List<X> {}
public class X {
void bar() {}
@SuppressWarnings({"unchecked"})
void test0(Supplier<List> sup) {
((Supplier<List<X>>) sup).get().get(0).bar();
}
@SuppressWarnings({"unchecked"})
void test1(Supplier<List> sup) {
((XListSupplier) sup).get().get(0).bar();
}
@SuppressWarnings({"unchecked"})
void test2(List list) {
((XList) list).get(0).bar();
list.get(0).bar();
}
}
"""
};
runner.expectedCompilerLog =
"""
----------
1. ERROR in X.java (at line 9)
((Supplier<List<X>>) sup).get().get(0).bar();
^^^^^^^^^^^^^^^^^^^^^^^^^
Cannot cast from Supplier<List> to Supplier<List<X>>
----------
2. ERROR in X.java (at line 13)
((XListSupplier) sup).get().get(0).bar();
^^^^^^^^^^^^^^^^^^^^^
Cannot cast from Supplier<List> to XListSupplier
----------
3. ERROR in X.java (at line 18)
list.get(0).bar();
^^^
The method bar() is undefined for the type Object
----------
""";
runner.runNegativeTest();
}

public static Class testClass() {
return CastTest.class;
}
Expand Down

0 comments on commit 5903df9

Please sign in to comment.