| 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 21281719674209128269d53a0165ed8d8cab6fd2..c074b7938c7aec46eabdae9302f15523b0dd0659 100644
|
| --- a/pkg/analyzer/lib/src/task/strong/checker.dart
|
| +++ b/pkg/analyzer/lib/src/task/strong/checker.dart
|
| @@ -163,6 +163,7 @@ class CodeChecker extends RecursiveAstVisitor {
|
| checkAssignment(expr.expression, type);
|
| } else {
|
| _checkDowncast(expr, type);
|
| + _checkNonNullAssignment(expr, type);
|
| }
|
| }
|
|
|
| @@ -613,11 +614,10 @@ class CodeChecker extends RecursiveAstVisitor {
|
| // typing rules may have inferred a more precise type for the variable
|
| // based on the initializer.
|
| } else {
|
| - var dartType = getType(type);
|
| for (VariableDeclaration variable in node.variables) {
|
| var initializer = variable.initializer;
|
| if (initializer != null) {
|
| - checkAssignment(initializer, dartType);
|
| + checkAssignment(initializer, type.type);
|
| }
|
| }
|
| }
|
| @@ -839,6 +839,14 @@ class CodeChecker extends RecursiveAstVisitor {
|
| [declElement.name]);
|
| }
|
|
|
| + void _checkNonNullAssignment(Expression expression, DartType type) {
|
| + var exprType = expression.staticType;
|
| + if (rules.isNonNullableType(type) && !rules.isNonNullableType(exprType)) {
|
| + _recordMessage(expression, StaticTypeWarningCode.INVALID_ASSIGNMENT,
|
| + [exprType, type]);
|
| + }
|
| + }
|
| +
|
| void _checkReturnOrYield(Expression expression, AstNode node,
|
| {bool yieldStar: false}) {
|
| FunctionBody body = node.getAncestor((n) => n is FunctionBody);
|
|
|