|
18 | 18 | import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
19 | 19 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
20 | 20 |
|
| 21 | +/** |
| 22 | + * Test class originally capturing issues specific to Java9, but meanwhile also just a continuation |
| 23 | + * of GenericsRegressionTest_1_8. |
| 24 | + */ |
21 | 25 | public class GenericsRegressionTest_9 extends AbstractRegressionTest9 { |
22 | 26 |
|
23 | 27 | static { |
@@ -1092,6 +1096,57 @@ public static <T> IQuery<T> createCompoundQuery(Collection<? extends IQuery<? ex |
1092 | 1096 | """ |
1093 | 1097 | }); |
1094 | 1098 | } |
| 1099 | +public void testGH3948() { |
| 1100 | + runNegativeTest(new String[] { |
| 1101 | + "Foo.java", |
| 1102 | + """ |
| 1103 | + import java.util.Collections; |
| 1104 | + import java.util.List; |
| 1105 | + import java.util.function.BiConsumer; |
| 1106 | + import java.util.function.Function; |
| 1107 | +
|
| 1108 | + public class Foo { |
| 1109 | + private List<? extends Bar> value; |
| 1110 | +
|
| 1111 | + public void set(List<? extends Bar> value) { |
| 1112 | + this.value = value; |
| 1113 | + } |
| 1114 | +
|
| 1115 | + public List<Bar> get() { |
| 1116 | + return Collections.unmodifiableList(value); |
| 1117 | + } |
| 1118 | +
|
| 1119 | + public static void main(String[] args) { |
| 1120 | + test(Foo::get, Foo::set); |
| 1121 | + } |
| 1122 | +
|
| 1123 | + public static <U> void test(Function<Foo, List<U>> getter, BiConsumer<Foo, List<? extends U>> setter) { |
| 1124 | + // noop |
| 1125 | + } |
| 1126 | +
|
| 1127 | + public static interface Bar{} |
| 1128 | + } |
| 1129 | + """ |
| 1130 | + }, |
| 1131 | + """ |
| 1132 | + ---------- |
| 1133 | + 1. ERROR in Foo.java (at line 18) |
| 1134 | + test(Foo::get, Foo::set); |
| 1135 | + ^^^^ |
| 1136 | + The method test(Function<Foo,List<U>>, BiConsumer<Foo,List<? extends U>>) in the type Foo is not applicable for the arguments (Foo::get, Foo::set) |
| 1137 | + ---------- |
| 1138 | + 2. ERROR in Foo.java (at line 18) |
| 1139 | + test(Foo::get, Foo::set); |
| 1140 | + ^^^^^^^^ |
| 1141 | + The type of get() from the type Foo is List<Foo.Bar>, this is incompatible with the descriptor's return type: List<U> |
| 1142 | + ---------- |
| 1143 | + 3. ERROR in Foo.java (at line 18) |
| 1144 | + test(Foo::get, Foo::set); |
| 1145 | + ^^^^^^^^ |
| 1146 | + The type Foo does not define set(Foo, List<capture#5-of ? extends U>) that is applicable here |
| 1147 | + ---------- |
| 1148 | + """); |
| 1149 | +} |
1095 | 1150 | public static Class<GenericsRegressionTest_9> testClass() { |
1096 | 1151 | return GenericsRegressionTest_9.class; |
1097 | 1152 | } |
|
0 commit comments