Chromium Code Reviews| Index: pkg/analyzer/lib/src/task/strong/checker.dart |
| diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart |
| index 8f2f12cf4926712a2392ae339ff6f5ce2cbaa234..5f16872c618f6c7446aacf0ff3b2c6d0fc2ef344 100644 |
| --- a/pkg/analyzer/lib/src/task/strong/checker.dart |
| +++ b/pkg/analyzer/lib/src/task/strong/checker.dart |
| @@ -341,6 +341,12 @@ class CodeChecker extends RecursiveAstVisitor { |
| } |
| @override |
| + void visitFieldDeclaration(FieldDeclaration node) { |
| + _checkForNonNullNotInitialized(node.fields); |
| + super.visitFieldDeclaration(node); |
| + } |
| + |
| + @override |
| void visitFieldFormalParameter(FieldFormalParameter node) { |
| var element = node.element; |
| var typeName = node.type; |
| @@ -602,6 +608,12 @@ class CodeChecker extends RecursiveAstVisitor { |
| } |
| @override |
| + Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| + _checkForNonNullNotInitialized(node.variables); |
| + return super.visitTopLevelVariableDeclaration(node); |
| + } |
| + |
| + @override |
| void visitSwitchStatement(SwitchStatement node) { |
| // SwitchStatement defines a boolean conversion to check the result of the |
| // case value == the switch value, but in dev_compiler we require a boolean |
| @@ -629,6 +641,12 @@ class CodeChecker extends RecursiveAstVisitor { |
| } |
| @override |
| + Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| + _checkForNonNullNotInitialized(node.variables); |
| + return super.visitVariableDeclarationStatement(node); |
| + } |
| + |
| + @override |
| void visitWhileStatement(WhileStatement node) { |
| checkBoolean(node.condition); |
| node.visitChildren(this); |
| @@ -745,6 +763,24 @@ class CodeChecker extends RecursiveAstVisitor { |
| } |
| /** |
| + * |
|
Jennifer Messerly
2016/08/05 17:39:31
missing doc comment here?
|
| + */ |
| + void _checkForNonNullNotInitialized(VariableDeclarationList list) { |
|
Jennifer Messerly
2016/08/05 17:39:31
you might be able to put this logic in visitVariab
stanm
2016/08/05 18:06:52
Awesome! Thanks!
|
| + NodeList<VariableDeclaration> variables = list.variables; |
| + for (VariableDeclaration variable in variables) { |
| + if (!list.isConst && |
| + !list.isFinal && |
| + variable.initializer == null && |
| + rules.isNonNullableType(list?.type?.type)) { |
| + _recordMessage( |
| + variable, |
| + StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED, |
| + [variable.name, list?.type?.type]); |
| + } |
| + } |
| + } |
| + |
| + /** |
| * Check if the closure [node] is unsafe due to dartbug.com/26947. If so, |
| * issue a warning. |
| * |