Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1090)

Unified Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 146733003: Handle type checking of generic compile time constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix for language/const_constructor3_test Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/const_constructor2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cc0eac63aafbc4f065a6449c07f68e46dd66af0f..2dfbb57f492623e0aeaf3515e3a700386c895c8f 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -774,8 +774,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);
@@ -807,6 +807,7 @@ class CompileTimeConstantEvaluator extends Visitor {
}
class ConstructorEvaluator extends CompileTimeConstantEvaluator {
+ final InterfaceType constructedType;
final FunctionElement constructor;
final Map<Element, Constant> definitions;
final Map<Element, Constant> fieldValues;
@@ -816,7 +817,8 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
*
* Invariant: [constructor] must be an implementation element.
*/
- ConstructorEvaluator(FunctionElement constructor,
+ ConstructorEvaluator(InterfaceType this.constructedType,
+ FunctionElement constructor,
ConstantCompiler handler,
Compiler compiler)
: this.constructor = constructor,
@@ -845,16 +847,12 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
TypedElement element,
Constant constant) {
if (compiler.enableTypeAssertions) {
- DartType elementType = element.type;
+ DartType elementType = element.type.substByContext(constructedType);
DartType constantType = constant.computeType(compiler);
- // TODO(ngeoffray): Handle type parameters.
- if (elementType.element.isTypeVariable()) return;
if (!constantSystem.isSubtype(compiler, constantType, elementType)) {
- // TODO(johnniwinther): Provide better [node] values that point to the
- // origin of the constant and not (just) the assignment.
compiler.reportFatalError(
node, MessageKind.NOT_ASSIGNABLE,
- {'fromType': elementType, 'toType': constantType});
+ {'fromType': constantType, 'toType': elementType});
}
}
}
@@ -871,9 +869,9 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator {
*/
void assignArgumentsToParameters(List<Constant> arguments) {
// Assign arguments to parameters.
- FunctionSignature parameters = constructor.functionSignature;
+ FunctionSignature signature = constructor.functionSignature;
int index = 0;
- parameters.orderedForEachParameter((Element parameter) {
+ signature.orderedForEachParameter((Element parameter) {
Constant argument = arguments[index++];
Node node = parameter.parseNode(compiler);
potentiallyCheckType(node, parameter, argument);
@@ -888,6 +886,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.
« no previous file with comments | « no previous file | tests/language/const_constructor2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698