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 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 onFailure(node, ambiguous.messageKind, ambiguous.messageArguments); | 1121 onFailure(node, ambiguous.messageKind, ambiguous.messageArguments); |
1122 } else if (!element.impliesType()) { | 1122 } else if (!element.impliesType()) { |
1123 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]); | 1123 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]); |
1124 } else { | 1124 } else { |
1125 if (identical(element, compiler.types.voidType.element) || | 1125 if (identical(element, compiler.types.voidType.element) || |
1126 identical(element, compiler.types.dynamicType.element)) { | 1126 identical(element, compiler.types.dynamicType.element)) { |
1127 type = element.computeType(compiler); | 1127 type = element.computeType(compiler); |
1128 } else if (element.isClass()) { | 1128 } else if (element.isClass()) { |
1129 ClassElement cls = element; | 1129 ClassElement cls = element; |
1130 cls.ensureResolved(compiler); | 1130 cls.ensureResolved(compiler); |
| 1131 cls.computeType(compiler); |
1131 Link<DartType> arguments = | 1132 Link<DartType> arguments = |
1132 resolveTypeArguments(node, cls.typeVariables, | 1133 resolveTypeArguments(node, cls.typeVariables, |
1133 inStaticContext, scope, | 1134 inStaticContext, scope, |
1134 onFailure, whenResolved); | 1135 onFailure, whenResolved); |
1135 if (cls.typeVariables.isEmpty && arguments.isEmpty) { | 1136 if (cls.typeVariables.isEmpty && arguments.isEmpty) { |
1136 // Use the canonical type if it has no type parameters. | 1137 // Use the canonical type if it has no type parameters. |
1137 type = cls.computeType(compiler); | 1138 type = cls.computeType(compiler); |
1138 } else { | 1139 } else { |
1139 // In checked mode malformed-ness of the type argument bubbles up. | 1140 // In checked mode malformed-ness of the type argument bubbles up. |
1140 if (anyMalformedTypesInThere(arguments) && | 1141 if (anyMalformedTypesInThere(arguments) && |
1141 compiler.enableTypeAssertions) { | 1142 compiler.enableTypeAssertions) { |
1142 type = new MalformedType( | 1143 type = new MalformedType( |
1143 new MalformedTypeElement(node, element)); | 1144 new MalformedTypeElement(node, element)); |
1144 } else { | 1145 } else { |
1145 type = new InterfaceType(cls.declaration, arguments); | 1146 if (arguments.isEmpty) { |
| 1147 // Use the canonical raw type if the class is generic. |
| 1148 type = cls.rawType; |
| 1149 } else { |
| 1150 type = new InterfaceType(cls.declaration, arguments); |
| 1151 } |
1146 } | 1152 } |
1147 } | 1153 } |
1148 } else if (element.isTypedef()) { | 1154 } else if (element.isTypedef()) { |
1149 TypedefElement typdef = element; | 1155 TypedefElement typdef = element; |
1150 // TODO(ahe): Should be [ensureResolved]. | 1156 // TODO(ahe): Should be [ensureResolved]. |
1151 compiler.resolveTypedef(typdef); | 1157 compiler.resolveTypedef(typdef); |
1152 typdef.computeType(compiler); | 1158 typdef.computeType(compiler); |
1153 Link<DartType> arguments = resolveTypeArguments( | 1159 Link<DartType> arguments = resolveTypeArguments( |
1154 node, typdef.typeVariables, inStaticContext, | 1160 node, typdef.typeVariables, inStaticContext, |
1155 scope, onFailure, whenResolved); | 1161 scope, onFailure, whenResolved); |
1156 if (typdef.typeVariables.isEmpty && arguments.isEmpty) { | 1162 if (typdef.typeVariables.isEmpty && arguments.isEmpty) { |
1157 // Return the canonical type if it has no type parameters. | 1163 // Return the canonical type if it has no type parameters. |
1158 type = typdef.computeType(compiler); | 1164 type = typdef.computeType(compiler); |
1159 } else { | 1165 } else { |
1160 type = new TypedefType(typdef, arguments); | 1166 if (arguments.isEmpty) { |
| 1167 type = typdef.rawType; |
| 1168 } else { |
| 1169 type = new TypedefType(typdef, arguments); |
| 1170 } |
1161 } | 1171 } |
1162 } else if (element.isTypeVariable()) { | 1172 } else if (element.isTypeVariable()) { |
1163 if (inStaticContext) { | 1173 if (inStaticContext) { |
1164 compiler.reportWarning(node, | 1174 compiler.reportWarning(node, |
1165 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER.message( | 1175 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER.message( |
1166 [element])); | 1176 [element])); |
1167 type = new MalformedType(new MalformedTypeElement(node, element)); | 1177 type = new MalformedType(new MalformedTypeElement(node, element)); |
1168 } else { | 1178 } else { |
1169 type = element.computeType(compiler); | 1179 type = element.computeType(compiler); |
1170 } | 1180 } |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 if (node.isRedirectingFactoryBody) { | 1964 if (node.isRedirectingFactoryBody) { |
1955 handleRedirectingFactoryBody(node); | 1965 handleRedirectingFactoryBody(node); |
1956 } else { | 1966 } else { |
1957 visit(node.expression); | 1967 visit(node.expression); |
1958 } | 1968 } |
1959 } | 1969 } |
1960 | 1970 |
1961 void handleRedirectingFactoryBody(Return node) { | 1971 void handleRedirectingFactoryBody(Return node) { |
1962 Element redirectionTarget = resolveRedirectingFactory(node); | 1972 Element redirectionTarget = resolveRedirectingFactory(node); |
1963 var type = mapping.getType(node.expression); | 1973 var type = mapping.getType(node.expression); |
1964 if (type is InterfaceType && !type.typeArguments.isEmpty) { | 1974 if (type is InterfaceType && !type.isRaw) { |
1965 unimplemented(node.expression, 'type arguments on redirecting factory'); | 1975 unimplemented(node.expression, 'type arguments on redirecting factory'); |
1966 } | 1976 } |
1967 useElement(node.expression, redirectionTarget); | 1977 useElement(node.expression, redirectionTarget); |
1968 assert(invariant(node, enclosingElement.isFactoryConstructor())); | 1978 assert(invariant(node, enclosingElement.isFactoryConstructor())); |
1969 FunctionElement constructor = enclosingElement; | 1979 FunctionElement constructor = enclosingElement; |
1970 if (constructor.modifiers.isConst() && | 1980 if (constructor.modifiers.isConst() && |
1971 !redirectionTarget.modifiers.isConst()) { | 1981 !redirectionTarget.modifiers.isConst()) { |
1972 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 1982 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
1973 } | 1983 } |
1974 // TODO(ahe): Check that this doesn't lead to a cycle. For now, | 1984 // TODO(ahe): Check that this doesn't lead to a cycle. For now, |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3140 return e; | 3150 return e; |
3141 } | 3151 } |
3142 | 3152 |
3143 /// Assumed to be called by [resolveRedirectingFactory]. | 3153 /// Assumed to be called by [resolveRedirectingFactory]. |
3144 Element visitReturn(Return node) { | 3154 Element visitReturn(Return node) { |
3145 Node expression = node.expression; | 3155 Node expression = node.expression; |
3146 return finishConstructorReference(visit(expression), | 3156 return finishConstructorReference(visit(expression), |
3147 expression, expression); | 3157 expression, expression); |
3148 } | 3158 } |
3149 } | 3159 } |
OLD | NEW |