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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * The [ConstantHandler] keeps track of compile-time constants, 8 * The [ConstantHandler] keeps track of compile-time constants,
9 * initializations of global and static fields, and default values of 9 * initializations of global and static fields, and default values of
10 * optional parameters. 10 * optional parameters.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 SendSet assignment = node.asSendSet(); 108 SendSet assignment = node.asSendSet();
109 Constant value; 109 Constant value;
110 if (assignment == null) { 110 if (assignment == null) {
111 // No initial value. 111 // No initial value.
112 value = new NullConstant(); 112 value = new NullConstant();
113 } else { 113 } else {
114 Node right = assignment.arguments.head; 114 Node right = assignment.arguments.head;
115 value = 115 value =
116 compileNodeWithDefinitions(right, definitions, isConst: isConst); 116 compileNodeWithDefinitions(right, definitions, isConst: isConst);
117 if (compiler.enableTypeAssertions 117 if (compiler.enableTypeAssertions &&
118 && value != null 118 value != null &&
119 && element.isField()) { 119 element.isField()) {
120 DartType elementType = element.computeType(compiler); 120 DartType elementType = element.computeType(compiler);
121 DartType constantType = value.computeType(compiler); 121 if (elementType.kind == TypeKind.MALFORMED_TYPE && !value.isNull()) {
122 if (!constantSystem.isSubtype(compiler, constantType, elementType)) { 122 // We need to throw an exception at runtime.
123 if (isConst) { 123 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.
124 compiler.reportFatalError( 124 } else {
125 node, MessageKind.NOT_ASSIGNABLE.error, 125 DartType constantType = value.computeType(compiler);
126 {'fromType': constantType, 'toType': elementType}); 126 if (!constantSystem.isSubtype(compiler,
127 } else { 127 constantType, elementType)) {
128 // If the field cannot be lazily initialized, we will throw 128 if (isConst) {
129 // the exception at runtime. 129 compiler.reportFatalError(
130 value = null; 130 node, MessageKind.NOT_ASSIGNABLE.error,
131 {'fromType': constantType, 'toType': elementType});
132 } else {
133 // If the field cannot be lazily initialized, we will throw
134 // the exception at runtime.
135 value = null;
136 }
131 } 137 }
132 } 138 }
133 } 139 }
134 } 140 }
135 if (value != null) { 141 if (value != null) {
136 initialVariableValues[element] = value; 142 initialVariableValues[element] = value;
137 } else { 143 } else {
138 assert(!isConst); 144 assert(!isConst);
139 lazyStatics.add(element); 145 lazyStatics.add(element);
140 } 146 }
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 if (fieldValue == null) { 957 if (fieldValue == null) {
952 // Use the default value. 958 // Use the default value.
953 fieldValue = handler.compileConstant(field); 959 fieldValue = handler.compileConstant(field);
954 } 960 }
955 jsNewArguments.add(fieldValue); 961 jsNewArguments.add(fieldValue);
956 }, 962 },
957 includeSuperAndInjectedMembers: true); 963 includeSuperAndInjectedMembers: true);
958 return jsNewArguments; 964 return jsNewArguments;
959 } 965 }
960 } 966 }
OLDNEW
« 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