Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: pkg/analyzer/test/src/task/strong/non_null_checker_test.dart

Issue 2302573003: Check for non-null assignment when checking casts (Closed) Base URL: https://github.com/dart-lang/sdk@master
Patch Set: Add tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/checker.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/strong/checker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698