OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 // These tests are for an experimental feature that treats Dart primitive types | 5 // These tests are for an experimental feature that treats Dart primitive types |
6 // (int, bool, double, etc.) as non-nullable. This file is not evidence for an | 6 // (int, bool, double, etc.) as non-nullable. This file is not evidence for an |
7 // intention to officially support non-nullable primitives in Dart (or general | 7 // intention to officially support non-nullable primitives in Dart (or general |
8 // NNBD, for that matter) so don't get too crazy about it. | 8 // NNBD, for that matter) so don't get too crazy about it. |
9 | 9 |
10 library analyzer.test.src.task.non_null_primitives.checker_test; | 10 library analyzer.test.src.task.non_null_primitives.checker_test; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 main() { | 100 main() { |
101 var languages = new MyList(); | 101 var languages = new MyList(); |
102 for (int i = 0; i < languages.length; ++i) { | 102 for (int i = 0; i < languages.length; ++i) { |
103 print(languages[i]); | 103 print(languages[i]); |
104 } | 104 } |
105 } | 105 } |
106 '''); | 106 '''); |
107 } | 107 } |
108 | 108 |
| 109 void test_compoundAssignment() { |
| 110 addFile(''' |
| 111 void main() { |
| 112 int i = 1; |
| 113 i += 2; |
| 114 /*error:STATIC_TYPE_ERROR*/i += null; |
| 115 print(i); |
| 116 } |
| 117 '''); |
| 118 check(nonnullableTypes: <String>['dart:core,int']); |
| 119 } |
| 120 |
| 121 void test_forEach() { |
| 122 addFile(''' |
| 123 void main() { |
| 124 var ints = <num>[1, 2, 3, null]; |
| 125 for (int /*error:INVALID_ASSIGNMENT*/i in ints) { |
| 126 print(i); |
| 127 } |
| 128 } |
| 129 '''); |
| 130 check(nonnullableTypes: <String>['dart:core,int']); |
| 131 } |
| 132 |
109 void test_initialize_nonnullable_with_null() { | 133 void test_initialize_nonnullable_with_null() { |
110 addFile('int x = /*error:INVALID_ASSIGNMENT*/null;'); | 134 addFile('int x = /*error:INVALID_ASSIGNMENT*/null;'); |
111 check(nonnullableTypes: <String>['dart:core,int']); | 135 check(nonnullableTypes: <String>['dart:core,int']); |
112 } | 136 } |
113 | 137 |
114 void test_initialize_nonnullable_with_valid_value() { | 138 void test_initialize_nonnullable_with_valid_value() { |
115 addFile('int x = 0;'); | 139 addFile('int x = 0;'); |
116 check(nonnullableTypes: <String>['dart:core,int']); | 140 check(nonnullableTypes: <String>['dart:core,int']); |
117 } | 141 } |
118 | 142 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 legs.insert("goat", 4); | 306 legs.insert("goat", 4); |
283 legs.insert("chicken", 2); | 307 legs.insert("chicken", 2); |
284 | 308 |
285 int x = legs.get("goat"); // This should not produce an error. | 309 int x = legs.get("goat"); // This should not produce an error. |
286 int y = legs.get("sheep"); // TODO(stanm): Runtime error here. | 310 int y = legs.get("sheep"); // TODO(stanm): Runtime error here. |
287 } | 311 } |
288 '''); | 312 '''); |
289 check(nonnullableTypes: <String>['dart:core,int']); | 313 check(nonnullableTypes: <String>['dart:core,int']); |
290 } | 314 } |
291 } | 315 } |
OLD | NEW |