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 c074b7938c7aec46eabdae9302f15523b0dd0659..956f1e380e23a3bb660c67bd2a3fbb02e7e12603 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)) { |
|
Leaf
2016/08/03 23:45:07
I'd suggest a helper "isNullableType", to avoid do
stanm
2016/08/04 00:31:15
Good idea, thanks!
|
| _recordMessage(expression, StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| [exprType, type]); |
| + return false; |
| } |
| + return true; |
| } |
| void _checkReturnOrYield(Expression expression, AstNode node, |