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

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

Issue 2208233002: Make LUB algorithm aware of non-null types (Closed) Base URL: https://github.com/dart-lang/sdk@nnp
Patch Set: Fix logic bug in isNullableType 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 c074b7938c7aec46eabdae9302f15523b0dd0659..7f61006e824bf8839e294e1440d0b62e95a2dc9f 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -162,8 +162,9 @@ class CodeChecker extends RecursiveAstVisitor {
if (expr is ParenthesizedExpression) {
checkAssignment(expr.expression, type);
} else {
- _checkDowncast(expr, type);
- _checkNonNullAssignment(expr, type);
+ if (_checkNonNullAssignment(expr, type)) {
+ _checkDowncast(expr, type);
+ }
}
}
@@ -839,12 +840,17 @@ class CodeChecker extends RecursiveAstVisitor {
[declElement.name]);
}
- void _checkNonNullAssignment(Expression expression, DartType type) {
+ /// Checks if the assignment is valid with respect to non-nullable types.
+ /// Returns `false` if a nullable expression is assigned to a variable of
+ /// non-nullable type and `true` otherwise.
+ bool _checkNonNullAssignment(Expression expression, DartType type) {
var exprType = expression.staticType;
- if (rules.isNonNullableType(type) && !rules.isNonNullableType(exprType)) {
+ if (rules.isNonNullableType(type) && rules.isNullableType(exprType)) {
_recordMessage(expression, StaticTypeWarningCode.INVALID_ASSIGNMENT,
[exprType, type]);
+ return false;
}
+ return true;
}
void _checkReturnOrYield(Expression expression, AstNode node,
« no previous file with comments | « pkg/analyzer/lib/src/generated/type_system.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