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 e7d3b7918f52c9bdb84e4aa8be8883f58f3cd861..121193a417e68dc04a107d6421e2d1d80476470a 100644 |
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart |
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart |
@@ -114,21 +114,33 @@ class ConstantHandler extends CompilerTask { |
Node right = assignment.arguments.head; |
value = |
compileNodeWithDefinitions(right, definitions, isConst: isConst); |
- if (compiler.enableTypeAssertions |
- && value != null |
- && element.isField()) { |
+ if (compiler.enableTypeAssertions && |
+ value != null && |
+ element.isField()) { |
DartType elementType = element.computeType(compiler); |
- DartType constantType = value.computeType(compiler); |
- if (!constantSystem.isSubtype(compiler, constantType, elementType)) { |
+ if (elementType.kind == TypeKind.MALFORMED_TYPE && !value.isNull()) { |
if (isConst) { |
+ ErroneousElement element = elementType.element; |
compiler.reportFatalError( |
- node, MessageKind.NOT_ASSIGNABLE.error, |
- {'fromType': constantType, 'toType': elementType}); |
+ node, element.messageKind, element.messageArguments); |
} else { |
- // If the field cannot be lazily initialized, we will throw |
- // the exception at runtime. |
+ // We need to throw an exception at runtime. |
value = null; |
} |
+ } else { |
+ DartType constantType = value.computeType(compiler); |
+ if (!constantSystem.isSubtype(compiler, |
+ constantType, elementType)) { |
+ if (isConst) { |
+ compiler.reportFatalError( |
+ node, MessageKind.NOT_ASSIGNABLE.error, |
+ {'fromType': constantType, 'toType': elementType}); |
+ } else { |
+ // If the field cannot be lazily initialized, we will throw |
+ // the exception at runtime. |
+ value = null; |
+ } |
+ } |
} |
} |
} |