Add type inference for invalid constructor initializers.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2998573002 .
This commit is contained in:
Paul Berry 2017-08-07 13:37:25 -07:00
parent 5011b024df
commit 107335c1d0
3 changed files with 21 additions and 1 deletions

View file

@ -3137,7 +3137,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
Initializer buildInvalidInitializer(Expression expression,
[int charOffset = -1]) {
needsImplicitSuperInitializer = false;
return new LocalInitializer(new VariableDeclaration.forValue(expression))
return new KernelInvalidInitializer(
new VariableDeclaration.forValue(expression))
..fileOffset = charOffset;
}

View file

@ -1019,6 +1019,19 @@ class KernelIntLiteral extends IntLiteral implements KernelExpression {
}
}
/// Concrete shadow object representing an invalid initializer in kernel form.
class KernelInvalidInitializer extends LocalInitializer
implements KernelInitializer {
KernelInvalidInitializer(VariableDeclaration variable) : super(variable);
@override
void _inferInitializer(KernelTypeInferrer inferrer) {
inferrer.listener.invalidInitializerEnter(this);
inferrer.inferExpression(variable.initializer, null, false);
inferrer.listener.invalidInitializerExit(this);
}
}
/// Concrete shadow object representing a non-inverted "is" test in kernel form.
class KernelIsExpression extends IsExpression implements KernelExpression {
KernelIsExpression(Expression operand, DartType type) : super(operand, type);

View file

@ -232,6 +232,12 @@ class TypeInferenceListener
void intLiteralExit(IntLiteral expression, DartType inferredType) =>
genericExpressionExit("intLiteral", expression, inferredType);
void invalidInitializerEnter(LocalInitializer initializer) =>
genericInitializerEnter("invalidInitializer", initializer);
void invalidInitializerExit(LocalInitializer initializer) =>
genericInitializerExit("invalidInitializer", initializer);
bool isExpressionEnter(IsExpression expression, DartType typeContext) =>
genericExpressionEnter("isExpression", expression, typeContext);