diff --git a/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart b/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart index 03877e465e3..d8cd2d89110 100644 --- a/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart +++ b/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart @@ -2984,7 +2984,7 @@ class _FlowAnalysisImpl context = _stack.removeLast() as _SimpleContext; - _current = _join(_current, context._previous); + _current = _merge(_current, context._previous); } @override @@ -2992,6 +2992,7 @@ class _FlowAnalysisImpl lhsInfo = _getExpressionInfo(leftHandSide); FlowModel promoted; + _current = _current.split(); if (lhsInfo is _VariableReadInfo) { ExpressionInfo promotionInfo = _current.tryMarkNonNullable(typeOperations, lhsInfo._variable); @@ -3156,12 +3157,13 @@ class _FlowAnalysisImpl context = _stack.removeLast() as _SimpleContext; - _current = _join(_current, context._previous); + _current = _merge(_current, context._previous); } @override bool nullAwareAccess_rightBegin(Expression target, Type targetType) { assert(targetType != null); + _current = _current.split(); _stack.add(new _NullAwareAccessContext(_current)); if (target != null) { ExpressionInfo targetInfo = _getExpressionInfo(target); diff --git a/pkg/_fe_analyzer_shared/test/flow_analysis/type_promotion/data/promotion_in_dead_code.dart b/pkg/_fe_analyzer_shared/test/flow_analysis/type_promotion/data/promotion_in_dead_code.dart index e8dfacdb1ea..3e56036d41c 100644 --- a/pkg/_fe_analyzer_shared/test/flow_analysis/type_promotion/data/promotion_in_dead_code.dart +++ b/pkg/_fe_analyzer_shared/test/flow_analysis/type_promotion/data/promotion_in_dead_code.dart @@ -6,6 +6,10 @@ // promotion continue to function properly even when used inside unreachable // code. +abstract class C { + void f(Object x, Object y); +} + conditionalIs(Object o) { return; o is int ? null : throw 'bad'; @@ -92,3 +96,15 @@ ifIsNot_mapElement(Object o) { ({if (o is! int) 0: throw 'x'}); /*int*/ o; } + +ifNull(Object o, Object? p, Object q, void Function(Object, Object) f) { + return; + (o is int ? p : throw 'x') ?? f(o = q, throw 'x'); + /*int*/ o; +} + +nullAwareAccess(Object o, C? p, Object q) { + return; + (o is int ? p : throw 'x')?.f(o = q, throw 'x'); + /*int*/ o; +}