| Index: pkg/compiler/lib/src/resolution/constructors.dart
|
| diff --git a/pkg/compiler/lib/src/resolution/constructors.dart b/pkg/compiler/lib/src/resolution/constructors.dart
|
| index 7b6808fcf4e62ec0c2cbc8d9857b1a76be2ba3a8..de5be38d6e3e7af0bb519d0a7aa95f1084d0af58 100644
|
| --- a/pkg/compiler/lib/src/resolution/constructors.dart
|
| +++ b/pkg/compiler/lib/src/resolution/constructors.dart
|
| @@ -8,6 +8,7 @@ import '../common.dart';
|
| import '../compiler.dart' show
|
| Compiler;
|
| import '../constants/constructors.dart' show
|
| + ErroneousConstantConstructor,
|
| GenerativeConstantConstructor,
|
| RedirectingGenerativeConstantConstructor;
|
| import '../constants/expressions.dart';
|
| @@ -131,12 +132,20 @@ class InitializerResolver {
|
| init.arguments.head,
|
| inConstantInitializer: isConst);
|
| if (isConst) {
|
| - if (result.isConstant && field != null) {
|
| - // TODO(johnniwinther): Report error if `result.constant` is `null`.
|
| - fieldInitializers[field] = result.constant;
|
| + ConstantExpression constant;
|
| + if (result.isConstant) {
|
| + constant = result.constant;
|
| } else {
|
| + if (field != null) {
|
| + reporter.reportErrorMessage(
|
| + init, MessageKind.NOT_A_COMPILE_TIME_CONSTANT);
|
| + }
|
| + constant = new ErroneousConstantExpression();
|
| isValidAsConstant = false;
|
| }
|
| + if (field != null) {
|
| + fieldInitializers[field] = constant;
|
| + }
|
| }
|
| }
|
|
|
| @@ -393,11 +402,16 @@ class InitializerResolver {
|
| } else {
|
| isValidAsConstant = false;
|
| }
|
| - if (isConst && isValidAsConstant) {
|
| - constructor.constantConstructor =
|
| - new RedirectingGenerativeConstantConstructor(
|
| - defaultValues,
|
| - constructorInvocation);
|
| + if (isConst) {
|
| + if (isValidAsConstant) {
|
| + constructor.constantConstructor =
|
| + new RedirectingGenerativeConstantConstructor(
|
| + defaultValues,
|
| + constructorInvocation);
|
| + } else {
|
| + constructor.constantConstructor =
|
| + const ErroneousConstantConstructor();
|
| + }
|
| }
|
| }
|
| return result.element;
|
| @@ -409,17 +423,43 @@ class InitializerResolver {
|
| } else {
|
| reporter.reportErrorMessage(
|
| link.head, MessageKind.INVALID_INITIALIZER);
|
| + isValidAsConstant = false;
|
| }
|
| }
|
| if (!resolvedSuper) {
|
| constructorInvocation = resolveImplicitSuperConstructorSend();
|
| }
|
| - if (isConst && isValidAsConstant) {
|
| - constructor.constantConstructor = new GenerativeConstantConstructor(
|
| - constructor.enclosingClass.thisType,
|
| - defaultValues,
|
| - fieldInitializers,
|
| - constructorInvocation);
|
| + if (isConst) {
|
| + ClassElement enclosingClass = constructor.enclosingClass;
|
| + enclosingClass.implementation.forEachInstanceField(
|
| + (ClassElement enclosingClass, FieldElementX field) {
|
| + if (field.isFinal) {
|
| + if (!fieldInitializers.containsKey(field)) {
|
| + visitor.compiler.resolver.resolveField(field);
|
| + Expression initializer = field.initializer;
|
| + if (initializer != null) {
|
| + fieldInitializers[field] = field.constant;
|
| + } else {
|
| + /*warning(functionNode, MessageKind.UNINITIALIZED_FINAL_FIELD, {
|
| + 'fieldName': field.name,
|
| + });*/
|
| + fieldInitializers[field] = new NullConstantExpression();
|
| + }
|
| + }
|
| + } else {
|
| + isValidAsConstant = false;
|
| + }
|
| + });
|
| + if (isValidAsConstant) {
|
| + constructor.constantConstructor = new GenerativeConstantConstructor(
|
| + enclosingClass.thisType,
|
| + defaultValues,
|
| + fieldInitializers,
|
| + constructorInvocation);
|
| + } else {
|
| + constructor.constantConstructor =
|
| + const ErroneousConstantConstructor();
|
| + }
|
| }
|
| return null; // If there was no redirection always return null.
|
| }
|
|
|