Ensure that ?? and ?. expressions promote properly in unreachable code.

Due to https://github.com/dart-lang/sdk/issues/43725 these have to be
updated in a single atomic CL.

Bug: https://github.com/dart-lang/sdk/issues/40009
Change-Id: Ifbd5fdee6379b7cbee5ab135f72a013134b70aa1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166601
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Paul Berry 2020-10-08 21:42:14 +00:00
parent 4182cbe1a3
commit ce7accb828
2 changed files with 20 additions and 2 deletions

View file

@ -2984,7 +2984,7 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
// common base class. See https://github.com/dart-lang/sdk/issues/43725.
_SimpleContext<Variable, Type> context =
_stack.removeLast() as _SimpleContext<Variable, Type>;
_current = _join(_current, context._previous);
_current = _merge(_current, context._previous);
}
@override
@ -2992,6 +2992,7 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
Expression leftHandSide, Type leftHandSideType) {
ExpressionInfo<Variable, Type> lhsInfo = _getExpressionInfo(leftHandSide);
FlowModel<Variable, Type> promoted;
_current = _current.split();
if (lhsInfo is _VariableReadInfo<Variable, Type>) {
ExpressionInfo<Variable, Type> promotionInfo =
_current.tryMarkNonNullable(typeOperations, lhsInfo._variable);
@ -3156,12 +3157,13 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
// common base class. See https://github.com/dart-lang/sdk/issues/43725.
_SimpleContext<Variable, Type> context =
_stack.removeLast() as _SimpleContext<Variable, Type>;
_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<Variable, Type>(_current));
if (target != null) {
ExpressionInfo<Variable, Type> targetInfo = _getExpressionInfo(target);

View file

@ -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;
}