OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library notnull; | 5 library notnull; |
6 | 6 |
7 void intAssignments() { | 7 void intAssignments() { |
8 var i = 0; | 8 var i = 0; |
9 i &= 1; | 9 i &= 1; |
10 i |= 1; | 10 i |= 1; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 int j = 1; | 88 int j = 1; |
89 j = i == 1 ? 1 : null; | 89 j = i == 1 ? 1 : null; |
90 print(j + 1); | 90 print(j + 1); |
91 } | 91 } |
92 | 92 |
93 void optParams([int x, int y = 1]) { | 93 void optParams([int x, int y = 1]) { |
94 print(x + y); | 94 print(x + y); |
95 } | 95 } |
96 | 96 |
97 void namedParams({int x, int y : 1}) { | 97 void namedParams({int x, int y: 1}) { |
98 print(x + y); | 98 print(x + y); |
99 } | 99 } |
100 | 100 |
101 void forLoops(int length()) { | 101 void forLoops(int length()) { |
102 for (int i = 0; i < 10; i++) { | 102 for (int i = 0; i < 10; i++) { |
103 print(i + 1); | 103 print(i + 1); |
104 } | 104 } |
105 for (int i = 0; i < length(); i++) { | 105 for (int i = 0; i < length(); i++) { |
106 print(i + 1); | 106 print(i + 1); |
107 } | 107 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } catch (e) { | 196 } catch (e) { |
197 print(e + 1); | 197 print(e + 1); |
198 } | 198 } |
199 try { | 199 try { |
200 (null as dynamic).foo(); | 200 (null as dynamic).foo(); |
201 } catch (e, trace) { | 201 } catch (e, trace) { |
202 print('${(e is String) ? e : e.toString()} at $trace'); | 202 print('${(e is String) ? e : e.toString()} at $trace'); |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
| 206 cascadesOnNull() { |
| 207 dynamic x = null; |
| 208 print((x |
| 209 ..toString() |
| 210 ..runtimeType) |
| 211 .hashCode); |
| 212 |
| 213 Object y = null; |
| 214 print((y |
| 215 ..toString() |
| 216 ..runtimeType) |
| 217 .hashCode); |
| 218 } |
| 219 |
206 main() { | 220 main() { |
207 intAssignments(); | 221 intAssignments(); |
208 doubleAssignments(); | 222 doubleAssignments(); |
209 boolAssignments(); | 223 boolAssignments(); |
210 nullableLocals(1); | 224 nullableLocals(1); |
211 optParams(1, 2); | 225 optParams(1, 2); |
212 namedParams(x: 1, y: 2); | 226 namedParams(x: 1, y: 2); |
213 forLoops(() => 10); | 227 forLoops(() => 10); |
214 increments(); | 228 increments(); |
215 conditionals(true); | 229 conditionals(true); |
216 calls(); | 230 calls(); |
217 localEscapes(); | 231 localEscapes(); |
218 controlFlow(); | 232 controlFlow(); |
| 233 cascadesOnNull(); |
219 | 234 |
220 nullableCycle(); | 235 nullableCycle(); |
221 nonNullableCycle(); | 236 nonNullableCycle(); |
222 } | 237 } |
OLD | NEW |