File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -205,11 +205,11 @@ abstract class FixBuilder extends GeneralizingAstVisitor<DartType> {
205205 case TokenType .QUESTION_QUESTION :
206206 // If `a ?? b` is used in a non-nullable context, we don't want to
207207 // migrate it to `(a ?? b)!`. We want to migrate it to `a ?? b!`.
208- // TODO(paulberry): once flow analysis supports `??`, integrate it here.
209- // See https://github.com/dart-lang/sdk/issues/38680
210208 var leftType = visitSubexpression (node.leftOperand,
211209 _typeSystem.makeNullable (_contextType as TypeImpl ));
210+ _flowAnalysis.ifNullExpression_rightBegin ();
212211 var rightType = visitSubexpression (node.rightOperand, _contextType);
212+ _flowAnalysis.ifNullExpression_end ();
213213 return _typeSystem.leastUpperBound (
214214 _typeSystem.promoteToNonNull (leftType as TypeImpl ), rightType);
215215 default :
Original file line number Diff line number Diff line change @@ -420,6 +420,17 @@ _f(int/*?*/ x, double/*?*/ y) {
420420 visitSubexpression (findNode.binary ('??' ), 'num?' );
421421 }
422422
423+ test_binaryExpression_question_question_flow () async {
424+ await analyze ('''
425+ _f(int/*?*/ x, int/*?*/ y) =>
426+ <dynamic>[x ?? (y != null ? 1 : throw 'foo'), y + 1];
427+ ''' );
428+ // The null check on the RHS of the `??` doesn't promote, because it is not
429+ // guaranteed to execute.
430+ visitSubexpression (findNode.listLiteral ('[' ), 'List<dynamic>' ,
431+ nullChecked: {findNode.simple ('y +' )});
432+ }
433+
423434 test_binaryExpression_question_question_nullChecked () async {
424435 await analyze ('''
425436Object/*!*/ _f(int/*?*/ x, double/*?*/ y) {
You can’t perform that action at this time.
0 commit comments