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

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

Issue 54983007: Make test of malformed types a dynamic type error. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes. Created 7 years, 1 month 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
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..fef91f69e9b433aaaab100fecea94ab88de0f21f 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -114,20 +114,26 @@ 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 (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;
+ if (elementType.kind == TypeKind.MALFORMED_TYPE && !value.isNull()) {
+ // We need to throw an exception at runtime.
+ value = null;
karlklose 2013/11/05 09:48:14 make sure there is a test for this.
Johnni Winther 2013/11/05 10:58:41 Done.
+ } 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;
+ }
}
}
}
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/elements/elements.dart » ('j') | sdk/lib/_internal/lib/js_helper.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698