Index: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart |
index 628ee9c38dfaa7b21039e9618ff7f6d7922f5208..c814760cd756139da1bd2ec1b7fcf7b4d5784b1c 100644 |
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart |
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart |
@@ -721,8 +721,8 @@ class CompileTimeConstantEvaluator extends Visitor { |
assert(invariant(node, constructor.isImplementation)); |
List<Constant> arguments = getArguments(constructor); |
- ConstructorEvaluator evaluator = |
- new ConstructorEvaluator(constructor, handler, compiler); |
+ ConstructorEvaluator evaluator = new ConstructorEvaluator( |
+ constructedType, constructor, handler, compiler); |
evaluator.evaluateConstructorFieldValues(arguments); |
List<Constant> jsNewArguments = evaluator.buildJsNewArguments(classElement); |
@@ -768,6 +768,7 @@ class TryCompileTimeConstantEvaluator extends CompileTimeConstantEvaluator { |
} |
class ConstructorEvaluator extends CompileTimeConstantEvaluator { |
+ final InterfaceType constructedType; |
final FunctionElement constructor; |
final Map<Element, Constant> definitions; |
final Map<Element, Constant> fieldValues; |
@@ -777,7 +778,8 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator { |
* |
* Invariant: [constructor] must be an implementation element. |
*/ |
- ConstructorEvaluator(FunctionElement constructor, |
+ ConstructorEvaluator(InterfaceType this.constructedType, |
+ FunctionElement constructor, |
ConstantHandler handler, |
Compiler compiler) |
: this.constructor = constructor, |
@@ -802,22 +804,25 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator { |
return super.visitSend(send); |
} |
- void potentiallyCheckType(Node node, Element element, Constant constant) { |
+ void potentiallyCheckType(Node node, |
karlklose
2014/01/29 10:44:23
'elementType' -> 'type'?
I think the name of the
Johnni Winther
2014/01/30 08:25:23
Done.
|
+ DartType elementType, |
+ Constant constant) { |
if (compiler.enableTypeAssertions) { |
- DartType elementType = element.computeType(compiler); |
DartType constantType = constant.computeType(compiler); |
- // TODO(ngeoffray): Handle type parameters. |
- if (elementType.element.isTypeVariable()) return; |
- if (!constantSystem.isSubtype(compiler, constantType, elementType)) { |
+ if (!compiler.types.isSubtype(constantType, elementType)) { |
compiler.reportFatalError( |
node, MessageKind.NOT_ASSIGNABLE.error, |
- {'fromType': elementType, 'toType': constantType}); |
+ {'fromType': constantType, 'toType': elementType}); |
} |
} |
} |
- void updateFieldValue(Node node, Element element, Constant constant) { |
- potentiallyCheckType(node, element, constant); |
+ void updateFieldValue(Node node, |
karlklose
2014/01/29 10:44:23
Still fits on one line.
Johnni Winther
2014/01/30 08:25:23
Done.
|
+ Element element, |
+ Constant constant) { |
+ DartType elementType = |
+ element.computeType(compiler).substByContext(constructedType); |
+ potentiallyCheckType(node, elementType, constant); |
fieldValues[element] = constant; |
} |
@@ -828,12 +833,14 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator { |
*/ |
void assignArgumentsToParameters(List<Constant> arguments) { |
// Assign arguments to parameters. |
- FunctionSignature parameters = constructor.computeSignature(compiler); |
+ FunctionSignature signature = constructor.computeSignature(compiler); |
int index = 0; |
- parameters.orderedForEachParameter((Element parameter) { |
+ signature.orderedForEachParameter((Element parameter) { |
+ DartType parameterType = |
+ parameter.computeType(compiler).substByContext(constructedType); |
Constant argument = arguments[index++]; |
Node node = parameter.parseNode(compiler); |
- potentiallyCheckType(node, parameter, argument); |
+ potentiallyCheckType(node, parameterType, argument); |
definitions[parameter] = argument; |
if (parameter.kind == ElementKind.FIELD_PARAMETER) { |
FieldParameterElement fieldParameterElement = parameter; |
@@ -845,6 +852,7 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator { |
void evaluateSuperOrRedirectSend(List<Constant> compiledArguments, |
FunctionElement targetConstructor) { |
ConstructorEvaluator evaluator = new ConstructorEvaluator( |
+ constructedType.asInstanceOf(targetConstructor.getEnclosingClass()), |
targetConstructor, handler, compiler); |
evaluator.evaluateConstructorFieldValues(compiledArguments); |
// Copy over the fieldValues from the super/redirect-constructor. |