1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8177466
   4  * @summary Add compiler support for local variable type-inference
   5  * @compile -source 9 ParserTest.java
   6  * @compile/fail/ref=ParserTest.out -XDrawDiagnostics ParserTest.java
   7  */
   8 
   9 import java.lang.annotation.ElementType;
  10 import java.lang.annotation.Target;
  11 import java.util.function.Function;
  12 import java.util.List;
  13 
  14 class ParserTest<var> {
  15     static class TestClass {
  16         static class var { } //illegal
  17     }
  18 
  19     static class TestInterface {
  20         interface var { } //illegal
  21     }
  22 
  23     static class TestEnum {
  24         enum var { } //illegal
  25     }
  26 
  27     static class TestAnno {
  28         @interface var { } //illegal
  29     }
  30 
  31     @Target(ElementType.TYPE_USE)
  32     @interface TA { }
  33 
  34     @interface DA { }
  35 
  36     static class var extends RuntimeException { } //illegal
  37 
  38     var x = null; //illegal
  39 
  40     void test() {
  41         var[] x1 = null; //illegal
  42         var x2[] = null; //illegal
  43         var[][] x3 = null; //illegal
  44         var x4[][] = null; //illegal
  45         var[] x5 = null; //illegal
  46         var x6[] = null; //illegal
  47         var@TA[]@TA[] x7 = null; //illegal
  48         var x8@TA[]@TA[] = null; //illegal
  49         var x9 = null, y = null; //illegal
  50         final @DA var x10 = m(); //ok
  51         @DA final var x11 = m(); //ok
  52     }
  53 
  54     var m() { //illegal
  55         return null;
  56     }
  57 
  58     void test2(var x) { //error
  59         List<var> l1; //error
  60         List<? extends var> l2; //error
  61         List<? super var> l3; //error
  62         try {
  63             Function<var, String> f = (var x2) -> ""; //error
  64         } catch (var ex) { } //error
  65     }
  66 
  67     void test3(Object o) {
  68         boolean b1 = o instanceof var; //error
  69         Object o2 = (var)o; //error
  70     }
  71 }