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

Side by Side Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 2219653005: Disallow uninitialized non-nullable variables (Closed) Base URL: https://github.com/dart-lang/sdk@master
Patch Set: Simplify 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
OLDNEW
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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
6 // refactored to fit into analyzer. 6 // refactored to fit into analyzer.
7 library analyzer.src.task.strong.checker; 7 library analyzer.src.task.strong.checker;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 var initializer = variable.initializer; 622 var initializer = variable.initializer;
623 if (initializer != null) { 623 if (initializer != null) {
624 checkAssignment(initializer, type.type); 624 checkAssignment(initializer, type.type);
625 } 625 }
626 } 626 }
627 } 627 }
628 node.visitChildren(this); 628 node.visitChildren(this);
629 } 629 }
630 630
631 @override 631 @override
632 Object visitVariableDeclaration(VariableDeclaration node) {
633 if (!node.isConst &&
634 !node.isFinal &&
635 node.initializer == null &&
636 rules.isNonNullableType(node?.element?.type)) {
637 _recordMessage(
638 node,
639 StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED,
640 [node.name, node?.element?.type]);
641 }
642 return super.visitVariableDeclaration(node);
643 }
644
645 @override
632 void visitWhileStatement(WhileStatement node) { 646 void visitWhileStatement(WhileStatement node) {
633 checkBoolean(node.condition); 647 checkBoolean(node.condition);
634 node.visitChildren(this); 648 node.visitChildren(this);
635 } 649 }
636 650
637 @override 651 @override
638 void visitYieldStatement(YieldStatement node) { 652 void visitYieldStatement(YieldStatement node) {
639 _checkReturnOrYield(node.expression, node, yieldStar: node.star != null); 653 _checkReturnOrYield(node.expression, node, yieldStar: node.star != null);
640 node.visitChildren(this); 654 node.visitChildren(this);
641 } 655 }
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 var visited = new Set<InterfaceType>(); 1503 var visited = new Set<InterfaceType>();
1490 do { 1504 do {
1491 visited.add(current); 1505 visited.add(current);
1492 current.mixins.reversed.forEach( 1506 current.mixins.reversed.forEach(
1493 (m) => _checkIndividualOverridesFromClass(node, m, seen, true)); 1507 (m) => _checkIndividualOverridesFromClass(node, m, seen, true));
1494 _checkIndividualOverridesFromClass(node, current.superclass, seen, true); 1508 _checkIndividualOverridesFromClass(node, current.superclass, seen, true);
1495 current = current.superclass; 1509 current = current.superclass;
1496 } while (!current.isObject && !visited.contains(current)); 1510 } while (!current.isObject && !visited.contains(current));
1497 } 1511 }
1498 } 1512 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/test/src/task/strong/non_null_checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698