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

Unified 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 side-by-side diff with in-line comments
Download patch
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..b20d702e71f4f1c4fa53b9c4974e48b22260857e 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -629,6 +629,20 @@ class CodeChecker extends RecursiveAstVisitor {
}
@override
+ Object visitVariableDeclaration(VariableDeclaration node) {
+ if (!node.isConst &&
+ !node.isFinal &&
+ node.initializer == null &&
+ rules.isNonNullableType(node?.element?.type)) {
+ _recordMessage(
+ node,
+ StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED,
+ [node.name, node?.element?.type]);
+ }
+ return super.visitVariableDeclaration(node);
+ }
+
+ @override
void visitWhileStatement(WhileStatement node) {
checkBoolean(node.condition);
node.visitChildren(this);
« 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