Chromium Code Reviews| Index: lib/compiler/implementation/compile_time_constants.dart |
| diff --git a/lib/compiler/implementation/compile_time_constants.dart b/lib/compiler/implementation/compile_time_constants.dart |
| index ac998f9c34c23ff24de6a0bf8664ef5380a77a67..2db1ab51e773888235246c511a95971f8d849526 100644 |
| --- a/lib/compiler/implementation/compile_time_constants.dart |
| +++ b/lib/compiler/implementation/compile_time_constants.dart |
| @@ -535,11 +535,16 @@ class CompileTimeConstantEvaluator extends AbstractVisitor { |
| return signalNotCompileTimeConstant(node); |
| } |
| - /** Returns the list of constants that are passed to the static function. */ |
| + /** |
| + * Returns the list of constants that are passed to the static function. |
| + * |
| + * Invariant: [target] must be an implementation element. |
| + */ |
| List<Constant> evaluateArgumentsToConstructor(Node node, |
| Selector selector, |
| Link<Node> arguments, |
| FunctionElement target) { |
| + assert(invariant(target, target.isImplementation)); |
|
ahe
2012/09/20 11:12:07
First argument should be node.
Johnni Winther
2012/09/21 09:18:25
Done.
|
| List<Constant> compiledArguments = <Constant>[]; |
| Function compileArgument = evaluateConstant; |
| @@ -571,6 +576,10 @@ class CompileTimeConstantEvaluator extends AbstractVisitor { |
| constructor = constructor.defaultImplementation; |
| classElement = constructor.getEnclosingClass(); |
| } |
| + // The constructor must be an implementation to ensure that field |
| + // initializers are handled correctly. |
| + constructor = constructor.implementation; |
| + assert(invariant(node, constructor.isImplementation)); |
| Selector selector = elements.getSelector(send); |
| List<Constant> arguments = evaluateArgumentsToConstructor( |
| @@ -626,10 +635,15 @@ class TryCompileTimeConstantEvaluator extends CompileTimeConstantEvaluator { |
| } |
| class ConstructorEvaluator extends CompileTimeConstantEvaluator { |
| - FunctionElement constructor; |
| + final FunctionElement constructor; |
| final Map<Element, Constant> definitions; |
| final Map<Element, Constant> fieldValues; |
| + /** |
| + * Documentation wanted -- johnniwinther |
| + * |
| + * Invariant: [constructor] must be an implementation element. |
| + */ |
| ConstructorEvaluator(FunctionElement constructor, |
| ConstantSystem constantSystem, |
| Compiler compiler) |
| @@ -637,9 +651,11 @@ class ConstructorEvaluator extends CompileTimeConstantEvaluator { |
| this.definitions = new Map<Element, Constant>(), |
| this.fieldValues = new Map<Element, Constant>(), |
| super(constantSystem, |
| - compiler.resolver.resolveMethodElement(constructor), |
| + compiler.resolver.resolveMethodElement(constructor.declaration), |
| compiler, |
| - isConst: true); |
| + isConst: true) { |
| + assert(invariant(constructor, constructor.isImplementation)); |
| + } |
| Constant visitSend(Send send) { |
| Element element = elements[send]; |