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 resolution; | 5 part of resolution; |
6 | 6 |
7 abstract class TreeElements { | 7 abstract class TreeElements { |
8 Element operator[](Node node); | 8 Element operator[](Node node); |
9 Selector getSelector(Send send); | 9 Selector getSelector(Send send); |
10 DartType getType(Node node); | 10 DartType getType(Node node); |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 breakTargetStack = breakTargetStack.tail; | 1031 breakTargetStack = breakTargetStack.tail; |
1032 labels = labels.outer; | 1032 labels = labels.outer; |
1033 } | 1033 } |
1034 } | 1034 } |
1035 | 1035 |
1036 class TypeResolver { | 1036 class TypeResolver { |
1037 final Compiler compiler; | 1037 final Compiler compiler; |
1038 | 1038 |
1039 TypeResolver(this.compiler); | 1039 TypeResolver(this.compiler); |
1040 | 1040 |
1041 bool anyMalformedTypesInThere(Link<DartType> list) { | 1041 bool anyMalformedTypes(Link<DartType> list) { |
1042 for (Link<DartType> link = list; | 1042 for (Link<DartType> link = list; |
1043 !link.isEmpty; | 1043 !link.isEmpty; |
1044 link = link.tail) { | 1044 link = link.tail) { |
1045 DartType dtype = link.head; | 1045 DartType dtype = link.head; |
1046 if (dtype is MalformedType) { | 1046 if (dtype is MalformedType) { |
1047 return true; | 1047 return true; |
1048 } | 1048 } |
1049 } | 1049 } |
1050 return false; | 1050 return false; |
1051 } | 1051 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 ClassElement cls = element; | 1129 ClassElement cls = element; |
1130 cls.ensureResolved(compiler); | 1130 cls.ensureResolved(compiler); |
1131 Link<DartType> arguments = | 1131 Link<DartType> arguments = |
1132 resolveTypeArguments(node, cls.typeVariables, | 1132 resolveTypeArguments(node, cls.typeVariables, |
1133 inStaticContext, scope, | 1133 inStaticContext, scope, |
1134 onFailure, whenResolved); | 1134 onFailure, whenResolved); |
1135 if (cls.typeVariables.isEmpty && arguments.isEmpty) { | 1135 if (cls.typeVariables.isEmpty && arguments.isEmpty) { |
1136 // Use the canonical type if it has no type parameters. | 1136 // Use the canonical type if it has no type parameters. |
1137 type = cls.computeType(compiler); | 1137 type = cls.computeType(compiler); |
1138 } else { | 1138 } else { |
1139 // In checked mode malformed-ness of the type argument bubbles up. | 1139 if (anyMalformedTypes(arguments)) { |
1140 if (anyMalformedTypesInThere(arguments) && | 1140 // Build interface type (with malformed arguments in it) and |
1141 compiler.enableTypeAssertions) { | 1141 // call [whenResolved] to let [ConstructorResolver] create |
1142 type = new MalformedType( | 1142 // constructor selectors, which are used by |
1143 new MalformedTypeElement(node, element)); | 1143 // [SsaBuilder.visitNewSend] to figure out what class needs |
| 1144 // to be built. |
| 1145 whenResolved(node, |
| 1146 new InterfaceType(cls.declaration, arguments)); |
| 1147 // Return malformed type element below so that |
| 1148 // [ConstructorResolver.visitTypeAnnotation] gets [:MalformedType:] |
| 1149 // and can map (via resolver.mapping) NewExpression node to |
| 1150 // this malformed type. |
| 1151 // [SsaBuilder.visitNewExpression] picks up the fact that |
| 1152 // NewExpression is mapped to malformed type and generates |
| 1153 // runtime error in checked mode. |
| 1154 type = new MalformedType(new MalformedTypeElement(node, element)); |
| 1155 return type; |
1144 } else { | 1156 } else { |
1145 if (arguments.isEmpty) { | 1157 if (arguments.isEmpty) { |
1146 // Use the canonical raw type if the class is generic. | 1158 // Use the canonical raw type if the class is generic. |
1147 type = cls.rawType; | 1159 type = cls.rawType; |
1148 } else { | 1160 } else { |
1149 type = new InterfaceType(cls.declaration, arguments); | 1161 type = new InterfaceType(cls.declaration, arguments); |
1150 } | 1162 } |
1151 } | 1163 } |
1152 } | 1164 } |
1153 } else if (element.isTypedef()) { | 1165 } else if (element.isTypedef()) { |
(...skipping 2005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3159 return e; | 3171 return e; |
3160 } | 3172 } |
3161 | 3173 |
3162 /// Assumed to be called by [resolveRedirectingFactory]. | 3174 /// Assumed to be called by [resolveRedirectingFactory]. |
3163 Element visitReturn(Return node) { | 3175 Element visitReturn(Return node) { |
3164 Node expression = node.expression; | 3176 Node expression = node.expression; |
3165 return finishConstructorReference(visit(expression), | 3177 return finishConstructorReference(visit(expression), |
3166 expression, expression); | 3178 expression, expression); |
3167 } | 3179 } |
3168 } | 3180 } |
OLD | NEW |