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

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

Issue 2200263004: Disallow assigning null to non-nullable variables (Closed) Base URL: https://github.com/dart-lang/sdk@master
Patch Set: Address lgtm comment Created 4 years, 4 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 27 matching lines...) Expand all
38 var languages = new MyList(); 38 var languages = new MyList();
39 for (int i = 0; i < languages.length; ++i) { 39 for (int i = 0; i < languages.length; ++i) {
40 print(languages[i]); 40 print(languages[i]);
41 } 41 }
42 } 42 }
43 '''); 43 ''');
44 } 44 }
45 45
46 void test_nullableTypes() { 46 void test_nullableTypes() {
47 // By default x can be set to null. 47 // By default x can be set to null.
48 checkFile('''int x = null;'''); 48 checkFile('int x = null;');
49 } 49 }
50 50
51 @failingTest
52 void test_nonnullableTypes() { 51 void test_nonnullableTypes() {
53 // If `int`s are non-nullable, then this code should throw an error. 52 // If `int`s are non-nullable, then this code should throw an error.
54 addFile('''int x = /*error:INVALID_ASSIGNMENT*/null;'''); 53 addFile('int x;');
54 addFile('int x = /*error:INVALID_ASSIGNMENT*/null;');
55 addFile('int x = 0;');
56 addFile('''
57 int x = 0;
58
59 main() {
60 x = 1;
61 x = /*error:INVALID_ASSIGNMENT*/null;
62 }
63 ''');
55 check(nonnullableTypes: <String>['dart:core,int']); 64 check(nonnullableTypes: <String>['dart:core,int']);
56 } 65 }
57 } 66 }
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