mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Convert ShadowIfNullExpression to IfNullJudgment
Change-Id: Id61c657b9eaf0e390e9f75c5ab711323a5212bbb Reviewed-on: https://dart-review.googlesource.com/61825 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
parent
7c327c32b7
commit
6fd40725af
3 changed files with 17 additions and 11 deletions
|
@ -1075,7 +1075,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
|
|||
Expression b = popForValue();
|
||||
Expression a = popForValue();
|
||||
VariableDeclaration variable = new VariableDeclaration.forValue(a);
|
||||
push(new ShadowIfNullExpression(
|
||||
push(new IfNullJudgment(
|
||||
variable,
|
||||
forest.conditionalExpression(
|
||||
buildIsNull(new VariableGet(variable), offsetForToken(token), this),
|
||||
|
|
|
@ -79,7 +79,7 @@ export 'kernel_shadow_ast.dart'
|
|||
ForInJudgment,
|
||||
ShadowFunctionDeclaration,
|
||||
ShadowFunctionExpression,
|
||||
ShadowIfNullExpression,
|
||||
IfNullJudgment,
|
||||
IfJudgment,
|
||||
IllegalAssignmentJudgment,
|
||||
IndexAssignmentJudgment,
|
||||
|
|
|
@ -1338,42 +1338,48 @@ class ShadowFunctionExpression extends FunctionExpression
|
|||
/// expression:
|
||||
///
|
||||
/// let v = a in v == null ? b : v
|
||||
class ShadowIfNullExpression extends Let implements ExpressionJudgment {
|
||||
class IfNullJudgment extends Let implements ExpressionJudgment {
|
||||
DartType inferredType;
|
||||
|
||||
ShadowIfNullExpression(VariableDeclaration variable, Expression body)
|
||||
IfNullJudgment(VariableDeclaration variable, Expression body)
|
||||
: super(variable, body);
|
||||
|
||||
@override
|
||||
ConditionalExpression get body => super.body;
|
||||
|
||||
/// Returns the expression to the left of `??`.
|
||||
Expression get _lhs => variable.initializer;
|
||||
ExpressionJudgment get leftJudgment => variable.initializer;
|
||||
|
||||
/// Returns the expression to the right of `??`.
|
||||
Expression get _rhs => body.then;
|
||||
ExpressionJudgment get rightJudgment => body.then;
|
||||
|
||||
@override
|
||||
DartType infer<Expression, Statement, Initializer, Type>(
|
||||
ShadowTypeInferrer inferrer,
|
||||
Factory<Expression, Statement, Initializer, Type> factory,
|
||||
DartType typeContext) {
|
||||
var leftJudgment = this.leftJudgment;
|
||||
var rightJudgment = this.rightJudgment;
|
||||
// To infer `e0 ?? e1` in context K:
|
||||
// - Infer e0 in context K to get T0
|
||||
var lhsType = inferrer.inferExpression(factory, _lhs, typeContext, true);
|
||||
inferrer.inferExpression(factory, leftJudgment, typeContext, true);
|
||||
var lhsType = leftJudgment.inferredType;
|
||||
if (inferrer.strongMode) {
|
||||
variable.type = lhsType;
|
||||
}
|
||||
// - Let J = T0 if K is `?` else K.
|
||||
// - Infer e1 in context J to get T1
|
||||
bool useLub = _forceLub || typeContext is UnknownType;
|
||||
var rhsType = typeContext is UnknownType
|
||||
? inferrer.inferExpression(factory, _rhs, lhsType, true)
|
||||
: inferrer.inferExpression(factory, _rhs, typeContext, _forceLub);
|
||||
if (typeContext is UnknownType) {
|
||||
inferrer.inferExpression(factory, rightJudgment, lhsType, true);
|
||||
} else {
|
||||
inferrer.inferExpression(factory, rightJudgment, typeContext, _forceLub);
|
||||
}
|
||||
var rhsType = rightJudgment.inferredType;
|
||||
// - Let T = greatest closure of K with respect to `?` if K is not `_`, else
|
||||
// UP(t0, t1)
|
||||
// - Then the inferred type is T.
|
||||
var inferredType = useLub
|
||||
inferredType = useLub
|
||||
? inferrer.typeSchemaEnvironment.getLeastUpperBound(lhsType, rhsType)
|
||||
: greatestClosure(inferrer.coreTypes, typeContext);
|
||||
if (inferrer.strongMode) {
|
||||
|
|
Loading…
Reference in a new issue