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

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: Updated cf. comments. 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)) {
123 if (isConst) { 122 if (isConst) {
123 ErroneousElement element = elementType.element;
124 compiler.reportFatalError( 124 compiler.reportFatalError(
125 node, MessageKind.NOT_ASSIGNABLE.error, 125 node, element.messageKind, element.messageArguments);
126 {'fromType': constantType, 'toType': elementType});
127 } else { 126 } else {
128 // If the field cannot be lazily initialized, we will throw 127 // We need to throw an exception at runtime.
129 // the exception at runtime.
130 value = null; 128 value = null;
131 } 129 }
130 } else {
131 DartType constantType = value.computeType(compiler);
132 if (!constantSystem.isSubtype(compiler,
133 constantType, elementType)) {
134 if (isConst) {
135 compiler.reportFatalError(
136 node, MessageKind.NOT_ASSIGNABLE.error,
137 {'fromType': constantType, 'toType': elementType});
138 } else {
139 // If the field cannot be lazily initialized, we will throw
140 // the exception at runtime.
141 value = null;
142 }
143 }
132 } 144 }
133 } 145 }
134 } 146 }
135 if (value != null) { 147 if (value != null) {
136 initialVariableValues[element] = value; 148 initialVariableValues[element] = value;
137 } else { 149 } else {
138 assert(!isConst); 150 assert(!isConst);
139 lazyStatics.add(element); 151 lazyStatics.add(element);
140 } 152 }
141 pendingVariables.remove(element); 153 pendingVariables.remove(element);
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 if (fieldValue == null) { 963 if (fieldValue == null) {
952 // Use the default value. 964 // Use the default value.
953 fieldValue = handler.compileConstant(field); 965 fieldValue = handler.compileConstant(field);
954 } 966 }
955 jsNewArguments.add(fieldValue); 967 jsNewArguments.add(fieldValue);
956 }, 968 },
957 includeSuperAndInjectedMembers: true); 969 includeSuperAndInjectedMembers: true);
958 return jsNewArguments; 970 return jsNewArguments;
959 } 971 }
960 } 972 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698