Skip to content

Commit a7b0f51

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: implement "why not promoted" logic for compound assignments.
Bug: #44898 Change-Id: I57a2c62b8450c313887b516d6fe2ef85fdd0d92b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193084 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 79bf4f3 commit a7b0f51

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

pkg/_fe_analyzer_shared/test/flow_analysis/why_not_promoted/data/argument_type_not_assignable_nullability_error.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,15 @@ forAssignmentInitializer(C25 c, int i) {
389389
null: null
390390
});
391391
}
392+
393+
class C26 {
394+
int? bad;
395+
}
396+
397+
compoundAssignmentRhs(C26 c) {
398+
int i = 0;
399+
if (c.bad == null) return;
400+
i +=
401+
/*analyzer.notPromoted(propertyNotPromoted(target: member:C26.bad, type: int?))*/ c
402+
. /*cfe.notPromoted(propertyNotPromoted(target: member:C26.bad, type: int?))*/ bad;
403+
}

pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ class AssignmentExpressionResolver {
248248
assignedType,
249249
whyNotPromoted: operator == TokenType.EQ ? whyNotPromoted : null,
250250
);
251+
if (operator != TokenType.EQ &&
252+
operator != TokenType.QUESTION_QUESTION_EQ) {
253+
_resolver.checkForArgumentTypeNotAssignableForArgument(node.rightHandSide,
254+
whyNotPromoted: whyNotPromoted);
255+
}
251256
}
252257

253258
void _setRhsContext(AssignmentExpressionImpl node, DartType leftType,

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
345345
void visitAssignmentExpression(AssignmentExpression node) {
346346
TokenType operatorType = node.operator.type;
347347
Expression lhs = node.leftHandSide;
348-
Expression rhs = node.rightHandSide;
349-
if (operatorType == TokenType.EQ ||
350-
operatorType == TokenType.QUESTION_QUESTION_EQ) {
351-
} else {
352-
checkForArgumentTypeNotAssignableForArgument(rhs);
353-
}
354348
if (operatorType == TokenType.QUESTION_QUESTION_EQ) {
355349
_checkForDeadNullCoalesce(node.readType as TypeImpl, node.rightHandSide);
356350
}

0 commit comments

Comments
 (0)