Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * @test /nodynamiccopyright/ |
aoqi@0 | 3 | * @bug 8003280 |
aoqi@0 | 4 | * @summary Add lambda tests |
aoqi@0 | 5 | * check that lambda cannot shadow variables from enclosing scope |
aoqi@0 | 6 | * @compile/fail/ref=LambdaScope04.out -XDrawDiagnostics LambdaScope04.java |
aoqi@0 | 7 | */ |
aoqi@0 | 8 | |
aoqi@0 | 9 | class LambdaScope04 { |
aoqi@0 | 10 | |
aoqi@0 | 11 | interface SAM { |
aoqi@0 | 12 | void m(Object o); |
aoqi@0 | 13 | } |
aoqi@0 | 14 | |
aoqi@0 | 15 | static SAM field1 = field1->{}; //ok |
aoqi@0 | 16 | static SAM field2 = param->{ Object field2 = null; }; //ok |
aoqi@0 | 17 | |
aoqi@0 | 18 | SAM field3 = field3->{}; //ok |
aoqi@0 | 19 | SAM field4 = param->{ Object field4 = null; }; //ok |
aoqi@0 | 20 | |
aoqi@0 | 21 | { |
aoqi@0 | 22 | Object local = null; |
aoqi@0 | 23 | SAM s1 = local->{}; //error |
aoqi@0 | 24 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 25 | } |
aoqi@0 | 26 | |
aoqi@0 | 27 | static { |
aoqi@0 | 28 | Object local = null; |
aoqi@0 | 29 | SAM s1 = local->{}; //error |
aoqi@0 | 30 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 31 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 32 | } |
aoqi@0 | 33 | |
aoqi@0 | 34 | void testLocalInstance() { |
aoqi@0 | 35 | Object local = null; |
aoqi@0 | 36 | SAM s1 = local->{}; //error |
aoqi@0 | 37 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 38 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 39 | } |
aoqi@0 | 40 | |
aoqi@0 | 41 | static void testLocalStatic() { |
aoqi@0 | 42 | Object local = null; |
aoqi@0 | 43 | SAM s1 = local->{}; //error |
aoqi@0 | 44 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 45 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 46 | } |
aoqi@0 | 47 | |
aoqi@0 | 48 | void testParamInstance(Object local) { |
aoqi@0 | 49 | SAM s1 = local->{}; //error |
aoqi@0 | 50 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 51 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 52 | } |
aoqi@0 | 53 | |
aoqi@0 | 54 | static void testParamStatic(Object local) { |
aoqi@0 | 55 | SAM s1 = local->{}; //error |
aoqi@0 | 56 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 57 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 58 | } |
aoqi@0 | 59 | |
aoqi@0 | 60 | void testForInstance() { |
aoqi@0 | 61 | for (int local = 0; local != 0 ; local++) { |
aoqi@0 | 62 | SAM s1 = local->{}; //error |
aoqi@0 | 63 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 64 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 65 | } |
aoqi@0 | 66 | } |
aoqi@0 | 67 | |
aoqi@0 | 68 | static void testForStatic(Iterable<Object> elems) { |
aoqi@0 | 69 | for (int local = 0; local != 0 ; local++) { |
aoqi@0 | 70 | SAM s1 = local->{}; //error |
aoqi@0 | 71 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 72 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 73 | } |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | void testForEachInstance(Iterable<Object> elems) { |
aoqi@0 | 77 | for (Object local : elems) { |
aoqi@0 | 78 | SAM s1 = local->{}; //error |
aoqi@0 | 79 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 80 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 81 | } |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | static void testForEachStatic(Iterable<Object> elems) { |
aoqi@0 | 85 | for (Object local : elems) { |
aoqi@0 | 86 | SAM s1 = local->{}; //error |
aoqi@0 | 87 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 88 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 89 | } |
aoqi@0 | 90 | } |
aoqi@0 | 91 | |
aoqi@0 | 92 | void testCatchInstance() { |
aoqi@0 | 93 | try { } catch (Throwable local) { |
aoqi@0 | 94 | SAM s1 = local->{}; //error |
aoqi@0 | 95 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 96 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 97 | } |
aoqi@0 | 98 | } |
aoqi@0 | 99 | |
aoqi@0 | 100 | static void testCatchStatic(Iterable<Object> elems) { |
aoqi@0 | 101 | try { } catch (Throwable local) { |
aoqi@0 | 102 | SAM s1 = local->{}; //error |
aoqi@0 | 103 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 104 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 105 | } |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | void testTWRInstance(AutoCloseable res) { |
aoqi@0 | 109 | try (AutoCloseable local = res) { |
aoqi@0 | 110 | SAM s1 = local->{}; //error |
aoqi@0 | 111 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 112 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 113 | } finally { } |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | static void testTWRStatic(AutoCloseable res) { |
aoqi@0 | 117 | try (AutoCloseable local = res) { |
aoqi@0 | 118 | SAM s1 = local->{}; //error |
aoqi@0 | 119 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 120 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 121 | } finally { } |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | void testBlockLocalInstance() { |
aoqi@0 | 125 | Object local = null; |
aoqi@0 | 126 | { |
aoqi@0 | 127 | SAM s1 = local->{}; //error |
aoqi@0 | 128 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 129 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 130 | } |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | static void testBlockLocalStatic() { |
aoqi@0 | 134 | Object local = null; |
aoqi@0 | 135 | { |
aoqi@0 | 136 | SAM s1 = local->{}; //error |
aoqi@0 | 137 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 138 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 139 | } |
aoqi@0 | 140 | } |
aoqi@0 | 141 | |
aoqi@0 | 142 | void testSwitchLocalInstance(int i) { |
aoqi@0 | 143 | switch (i) { |
aoqi@0 | 144 | case 0: Object local = null; |
aoqi@0 | 145 | default: { |
aoqi@0 | 146 | SAM s1 = local->{}; //error |
aoqi@0 | 147 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 148 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 149 | } |
aoqi@0 | 150 | } |
aoqi@0 | 151 | } |
aoqi@0 | 152 | |
aoqi@0 | 153 | static void testSwitchLocalStatic(int i) { |
aoqi@0 | 154 | switch (i) { |
aoqi@0 | 155 | case 0: Object local = null; |
aoqi@0 | 156 | default: { |
aoqi@0 | 157 | SAM s1 = local->{}; //error |
aoqi@0 | 158 | SAM s2 = param->{ Object local = null; }; //error |
aoqi@0 | 159 | SAM s3 = field1->{ Object field_2 = null; }; //ok |
aoqi@0 | 160 | } |
aoqi@0 | 161 | } |
aoqi@0 | 162 | } |
aoqi@0 | 163 | } |