OLD | NEW |
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 value = new NullConstant(); | 127 value = new NullConstant(); |
128 } else { | 128 } else { |
129 Node right = assignment.arguments.head; | 129 Node right = assignment.arguments.head; |
130 value = | 130 value = |
131 compileNodeWithDefinitions(right, definitions, isConst: isConst); | 131 compileNodeWithDefinitions(right, definitions, isConst: isConst); |
132 if (compiler.enableTypeAssertions | 132 if (compiler.enableTypeAssertions |
133 && value != null | 133 && value != null |
134 && element.isField()) { | 134 && element.isField()) { |
135 DartType elementType = element.computeType(compiler); | 135 DartType elementType = element.computeType(compiler); |
136 DartType constantType = value.computeType(compiler); | 136 DartType constantType = value.computeType(compiler); |
137 if (!compiler.types.isSubtype(constantType, elementType)) { | 137 if (!constantSystem.isSubtype(compiler, constantType, elementType)) { |
138 if (isConst) { | 138 if (isConst) { |
139 MessageKind kind = MessageKind.NOT_ASSIGNABLE; | 139 MessageKind kind = MessageKind.NOT_ASSIGNABLE; |
140 compiler.reportError(node, new CompileTimeConstantError( | 140 compiler.reportError(node, new CompileTimeConstantError( |
141 kind, [elementType, constantType])); | 141 kind, [elementType, constantType])); |
142 } else { | 142 } else { |
143 // If the field can be lazily initialized, we will throw | 143 // If the field can be lazily initialized, we will throw |
144 // the exception at runtime. | 144 // the exception at runtime. |
145 value = null; | 145 value = null; |
146 } | 146 } |
147 } | 147 } |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 // Use the default value. | 823 // Use the default value. |
824 fieldValue = compiler.compileConstant(field); | 824 fieldValue = compiler.compileConstant(field); |
825 } | 825 } |
826 jsNewArguments.add(fieldValue); | 826 jsNewArguments.add(fieldValue); |
827 }, | 827 }, |
828 includeBackendMembers: true, | 828 includeBackendMembers: true, |
829 includeSuperMembers: true); | 829 includeSuperMembers: true); |
830 return jsNewArguments; | 830 return jsNewArguments; |
831 } | 831 } |
832 } | 832 } |
OLD | NEW |