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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 11412245: MalformedType used for all invalid type annotations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 Constant value; 123 Constant value;
124 if (assignment == null) { 124 if (assignment == null) {
125 // No initial value. 125 // No initial value.
126 value = new NullConstant(); 126 value = new NullConstant();
127 } else { 127 } else {
128 Node right = assignment.arguments.head; 128 Node right = assignment.arguments.head;
129 value = 129 value =
130 compileNodeWithDefinitions(right, definitions, isConst: isConst); 130 compileNodeWithDefinitions(right, definitions, isConst: isConst);
131 if (compiler.enableTypeAssertions 131 if (compiler.enableTypeAssertions
132 && value != null 132 && value != null
133 && element.isField()) { 133 && element.isField()) {
ngeoffray 2012/11/30 12:00:40 Maybe try to have this method call potentiallyChec
Johnni Winther 2012/12/04 10:07:17 I found no clean way to refactor.
134 DartType elementType = element.computeType(compiler); 134 DartType elementType = element.computeType(compiler);
135 DartType constantType = value.computeType(compiler); 135 DartType constantType = value.computeType(compiler);
136 if (!constantSystem.isSubtype(compiler, constantType, elementType)) { 136 if (elementType.isMalformed || constantType.isMalformed ||
137 !constantSystem.isSubtype(compiler, constantType, elementType)) {
137 if (isConst) { 138 if (isConst) {
138 MessageKind kind = MessageKind.NOT_ASSIGNABLE; 139 MessageKind kind = MessageKind.NOT_ASSIGNABLE;
139 compiler.reportError(node, new CompileTimeConstantError( 140 compiler.reportError(node, new CompileTimeConstantError(
140 kind, [elementType, constantType])); 141 kind, [elementType, constantType]));
141 } else { 142 } else {
142 // If the field can be lazily initialized, we will throw 143 // If the field can be lazily initialized, we will throw
143 // the exception at runtime. 144 // the exception at runtime.
144 value = null; 145 value = null;
145 } 146 }
146 } 147 }
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 } 707 }
707 return super.visitSend(send); 708 return super.visitSend(send);
708 } 709 }
709 710
710 void potentiallyCheckType(Node node, Element element, Constant constant) { 711 void potentiallyCheckType(Node node, Element element, Constant constant) {
711 if (compiler.enableTypeAssertions) { 712 if (compiler.enableTypeAssertions) {
712 DartType elementType = element.computeType(compiler); 713 DartType elementType = element.computeType(compiler);
713 DartType constantType = constant.computeType(compiler); 714 DartType constantType = constant.computeType(compiler);
714 // TODO(ngeoffray): Handle type parameters. 715 // TODO(ngeoffray): Handle type parameters.
715 if (elementType.element.isTypeVariable()) return; 716 if (elementType.element.isTypeVariable()) return;
716 if (!constantSystem.isSubtype(compiler, constantType, elementType)) { 717 if (elementType.isMalformed || constantType.isMalformed ||
718 !constantSystem.isSubtype(compiler, constantType, elementType)) {
717 MessageKind kind = MessageKind.NOT_ASSIGNABLE; 719 MessageKind kind = MessageKind.NOT_ASSIGNABLE;
718 compiler.reportError(node, new CompileTimeConstantError( 720 compiler.reportError(node, new CompileTimeConstantError(
719 kind, [elementType, constantType])); 721 kind, [elementType, constantType]));
720 } 722 }
721 } 723 }
722 } 724 }
723 725
724 void updateFieldValue(Node node, Element element, Constant constant) { 726 void updateFieldValue(Node node, Element element, Constant constant) {
725 potentiallyCheckType(node, element, constant); 727 potentiallyCheckType(node, element, constant);
726 fieldValues[element] = constant; 728 fieldValues[element] = constant;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 // Use the default value. 848 // Use the default value.
847 fieldValue = compiler.compileConstant(field); 849 fieldValue = compiler.compileConstant(field);
848 } 850 }
849 jsNewArguments.add(fieldValue); 851 jsNewArguments.add(fieldValue);
850 }, 852 },
851 includeBackendMembers: true, 853 includeBackendMembers: true,
852 includeSuperMembers: true); 854 includeSuperMembers: true);
853 return jsNewArguments; 855 return jsNewArguments;
854 } 856 }
855 } 857 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698