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

Side by Side Diff: lib/compiler/implementation/resolution/members.dart

Issue 11229002: Handle type variable in static member. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months 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 abstract class TreeElements { 5 abstract class TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 DartType getType(TypeAnnotation annotation); 8 DartType getType(TypeAnnotation annotation);
9 bool isParameterChecked(Element element); 9 bool isParameterChecked(Element element);
10 } 10 }
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 } 1079 }
1080 } else { 1080 } else {
1081 return scope.lookup(typeName.source); 1081 return scope.lookup(typeName.source);
1082 } 1082 }
1083 } 1083 }
1084 1084
1085 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean 1085 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean
1086 // flags instead of closures. 1086 // flags instead of closures.
1087 // TODO(johnniwinther): Should never return [null] but instead an erroneous 1087 // TODO(johnniwinther): Should never return [null] but instead an erroneous
1088 // type. 1088 // type.
1089 DartType resolveTypeAnnotation(TypeAnnotation node, 1089 DartType resolveTypeAnnotation(TypeAnnotation node, Scope scope,
karlklose 2012/10/19 12:05:38 Maybe put the first two arguments on their on line
Johnni Winther 2012/10/22 09:03:32 Done.
1090 {Scope inScope, ClassElement inClass, 1090 {onFailure(Node node, MessageKind kind, [List arguments]),
1091 onFailure(Node, MessageKind, [List arguments]), 1091 whenResolved(Node node, DartType type)}) {
1092 whenResolved(Node, Type)}) {
1093 if (onFailure == null) { 1092 if (onFailure == null) {
1094 onFailure = (n, k, [arguments]) {}; 1093 onFailure = (n, k, [arguments]) {};
1095 } 1094 }
1096 if (whenResolved == null) { 1095 if (whenResolved == null) {
1097 whenResolved = (n, t) {}; 1096 whenResolved = (n, t) {};
1098 } 1097 }
1099 if (inClass != null) { 1098 if (scope == null) {
1100 inScope = inClass.buildScope();
1101 }
1102 if (inScope == null) {
1103 compiler.internalError('resolveTypeAnnotation: no scope specified'); 1099 compiler.internalError('resolveTypeAnnotation: no scope specified');
1104 } 1100 }
1105 return resolveTypeAnnotationInContext(inScope, node, onFailure, 1101 return resolveTypeAnnotationInContext(scope, node, onFailure,
1106 whenResolved); 1102 whenResolved);
1107 } 1103 }
1108 1104
1109 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, 1105 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node,
1110 onFailure, whenResolved) { 1106 onFailure, whenResolved) {
1111 Element element = resolveTypeName(scope, node); 1107 Element element = resolveTypeName(scope, node);
1112 DartType type; 1108 DartType type;
1113 if (element == null) { 1109 if (element == null) {
1114 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); 1110 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
1115 } else if (element.isErroneous()) { 1111 } else if (element.isErroneous()) {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 } 1327 }
1332 } 1328 }
1333 return element; 1329 return element;
1334 } 1330 }
1335 1331
1336 Element useElement(Node node, Element element) { 1332 Element useElement(Node node, Element element) {
1337 if (element == null) return null; 1333 if (element == null) return null;
1338 return mapping[node] = element; 1334 return mapping[node] = element;
1339 } 1335 }
1340 1336
1341 DartType useType(TypeAnnotation annotation, DartType type) { 1337 DartType useType(TypeAnnotation annotation, DartType type) {
karlklose 2012/10/19 12:05:38 I think you should rename this helper.
Johnni Winther 2012/10/22 09:03:32 Renamed and doc added.
1342 if (type != null) { 1338 if (type != null) {
1343 mapping.setType(annotation, type); 1339 mapping.setType(annotation, type);
1344 useElement(annotation, type.element); 1340 useElement(annotation, type.element);
1341 if (type is TypeVariableType && enclosingElement.isInStaticMember()) {
ahe 2012/10/19 11:58:04 I would prefer using .kind over is tests. I would
Johnni Winther 2012/10/22 09:03:32 TypeKind added.
1342 error(annotation, MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1343 [type]);
karlklose 2012/10/19 12:05:38 Indentation is wrong.
Johnni Winther 2012/10/22 09:03:32 Done.
1344 }
1345 } 1345 }
1346 return type; 1346 return type;
1347 } 1347 }
1348 1348
1349 void setupFunction(FunctionExpression node, FunctionElement function) { 1349 void setupFunction(FunctionExpression node, FunctionElement function) {
1350 scope = new MethodScope(scope, function); 1350 scope = new MethodScope(scope, function);
1351 1351
1352 // Put the parameters in scope. 1352 // Put the parameters in scope.
1353 FunctionSignature functionParameters = 1353 FunctionSignature functionParameters =
1354 function.computeSignature(compiler); 1354 function.computeSignature(compiler);
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 } else if (argument is InterfaceType) { 1953 } else if (argument is InterfaceType) {
1954 InterfaceType type = argument; 1954 InterfaceType type = argument;
1955 type.arguments.forEach((DartType argument) { 1955 type.arguments.forEach((DartType argument) {
1956 analyzeTypeArgument(type, argument); 1956 analyzeTypeArgument(type, argument);
1957 }); 1957 });
1958 } 1958 }
1959 } 1959 }
1960 1960
1961 DartType resolveTypeAnnotation(TypeAnnotation node) { 1961 DartType resolveTypeAnnotation(TypeAnnotation node) {
1962 Function report = typeRequired ? error : warning; 1962 Function report = typeRequired ? error : warning;
1963 DartType type = typeResolver.resolveTypeAnnotation(node, inScope: scope, 1963 DartType type = typeResolver.resolveTypeAnnotation(node, scope,
1964 onFailure: report, 1964 onFailure: report,
1965 whenResolved: useType); 1965 whenResolved: useType);
1966 if (type == null) return null; 1966 if (type == null) return null;
1967 if (inCheckContext) { 1967 if (inCheckContext) {
1968 compiler.enqueuer.resolution.registerIsCheck(type); 1968 compiler.enqueuer.resolution.registerIsCheck(type);
1969 } 1969 }
1970 if (typeRequired || inCheckContext) { 1970 if (typeRequired || inCheckContext) {
1971 if (type is InterfaceType) { 1971 if (type is InterfaceType) {
1972 InterfaceType itf = type; 1972 InterfaceType itf = type;
1973 itf.arguments.forEach((DartType argument) { 1973 itf.arguments.forEach((DartType argument) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 SourceString typeName = typeVariable.name; 2305 SourceString typeName = typeVariable.name;
2306 TypeVariable typeNode = nodeLink.head; 2306 TypeVariable typeNode = nodeLink.head;
2307 if (nameSet.contains(typeName)) { 2307 if (nameSet.contains(typeName)) {
2308 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); 2308 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]);
2309 } 2309 }
2310 nameSet.add(typeName); 2310 nameSet.add(typeName);
2311 2311
2312 TypeVariableElement variableElement = typeVariable.element; 2312 TypeVariableElement variableElement = typeVariable.element;
2313 if (typeNode.bound != null) { 2313 if (typeNode.bound != null) {
2314 DartType boundType = typeResolver.resolveTypeAnnotation( 2314 DartType boundType = typeResolver.resolveTypeAnnotation(
2315 typeNode.bound, inScope: scope, onFailure: warning); 2315 typeNode.bound, scope, onFailure: warning);
2316 if (boundType != null && boundType.element == variableElement) { 2316 if (boundType != null && boundType.element == variableElement) {
2317 // TODO(johnniwinther): Check for more general cycles, like 2317 // TODO(johnniwinther): Check for more general cycles, like
2318 // [: <A extends B, B extends C, C extends B> :]. 2318 // [: <A extends B, B extends C, C extends B> :].
2319 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, 2319 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE,
2320 [variableElement.name]); 2320 [variableElement.name]);
2321 } else if (boundType != null) { 2321 } else if (boundType != null) {
2322 variableElement.bound = boundType; 2322 variableElement.bound = boundType;
2323 } else { 2323 } else {
2324 // TODO(johnniwinther): Should be an erroneous type. 2324 // TODO(johnniwinther): Should be an erroneous type.
2325 variableElement.bound = compiler.objectClass.computeType(compiler); 2325 variableElement.bound = compiler.objectClass.computeType(compiler);
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
3191 return result; 3191 return result;
3192 } 3192 }
3193 Element lookup(SourceString name) => localLookup(name); 3193 Element lookup(SourceString name) => localLookup(name);
3194 Element lexicalLookup(SourceString name) => localLookup(name); 3194 Element lexicalLookup(SourceString name) => localLookup(name);
3195 3195
3196 Element add(Element newElement) { 3196 Element add(Element newElement) {
3197 throw "Cannot add an element in a patch library scope"; 3197 throw "Cannot add an element in a patch library scope";
3198 } 3198 }
3199 String toString() => 'PatchLibraryScope($origin,$patch)'; 3199 String toString() => 'PatchLibraryScope($origin,$patch)';
3200 } 3200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698