1 /*
 2  * @test /nodynamiccopyright/
 3  * @bug 8244561 8250997
 4  * @summary Javac should not allow instantiation of V.ref or V.val
 5  * @compile/fail/ref=ProjectionInstantiationTest.out -XDrawDiagnostics ProjectionInstantiationTest.java
 6  */
 7 import java.util.function.Supplier;
 8 
 9 final class ProjectionInstantiationTest {
10 
11     static primitive class ValDefault {}
12 
13     static primitive class RefDefault.val<T> {}
14 
15     public static void main(String[] args) {
16 
17         // Next two instantiations are good.
18         var v1 = new ValDefault();
19         var v2 = new RefDefault<>();
20 
21         v1 = v2;
22 
23         // Next four instantiations are problematic
24         new ValDefault.ref();
25         new RefDefault.ref<>();
26         new ValDefault.val();
27         new RefDefault.val<>();
28 
29         // Next two references are good.
30         voo(ValDefault::new);
31         roo(RefDefault::new);
32 
33         // Next four references are problematic
34         voo(ValDefault.ref::new);
35         voo(ValDefault.val::new);
36         roo(RefDefault.ref::new);
37         roo(RefDefault.val::new);
38     }
39 
40     static void voo(Supplier<ValDefault.ref> sx) {
41         sx.get();
42     }
43 
44     static void roo(Supplier<RefDefault.ref> sx) {
45         sx.get();
46     }
47 }