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

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: Test update removed. 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(Node node); 8 DartType getType(Node node);
9 bool isParameterChecked(Element element); 9 bool isParameterChecked(Element element);
10 } 10 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // the error message below. 341 // the error message below.
342 error(node, 342 error(node,
343 MessageKind.CANNOT_FIND_CONSTRUCTOR2, 343 MessageKind.CANNOT_FIND_CONSTRUCTOR2,
344 [selector.name, defaultClass.name]); 344 [selector.name, defaultClass.name]);
345 } 345 }
346 } 346 }
347 347
348 TreeElements resolveField(VariableElement element) { 348 TreeElements resolveField(VariableElement element) {
349 Node tree = element.parseNode(compiler); 349 Node tree = element.parseNode(compiler);
350 if(element.modifiers.isStatic() && element.variables.isTopLevel()) { 350 if(element.modifiers.isStatic() && element.variables.isTopLevel()) {
351 error(element.modifiers.getStatic(), MessageKind.TOP_LEVEL_VARIABLE_DECLAR ED_STATIC); 351 error(element.modifiers.getStatic(),
352 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC);
352 } 353 }
353 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 354 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
354 initializerDo(tree, visitor.visit); 355 initializerDo(tree, visitor.visit);
355 return visitor.mapping; 356 return visitor.mapping;
356 } 357 }
357 358
358 TreeElements resolveParameter(Element element) { 359 TreeElements resolveParameter(Element element) {
359 Node tree = element.parseNode(compiler); 360 Node tree = element.parseNode(compiler);
360 ResolverVisitor visitor = 361 ResolverVisitor visitor =
361 new ResolverVisitor(compiler, element.enclosingElement); 362 new ResolverVisitor(compiler, element.enclosingElement);
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 } 1079 }
1079 } else { 1080 } else {
1080 return scope.lookup(typeName.source); 1081 return scope.lookup(typeName.source);
1081 } 1082 }
1082 } 1083 }
1083 1084
1084 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean 1085 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean
1085 // flags instead of closures. 1086 // flags instead of closures.
1086 // TODO(johnniwinther): Should never return [null] but instead an erroneous 1087 // TODO(johnniwinther): Should never return [null] but instead an erroneous
1087 // type. 1088 // type.
1088 DartType resolveTypeAnnotation(TypeAnnotation node, 1089 DartType resolveTypeAnnotation(
1089 {Scope inScope, ClassElement inClass, 1090 TypeAnnotation node,
1090 onFailure(Node, MessageKind, [List arguments]), 1091 Scope scope,
1091 whenResolved(Node, Type)}) { 1092 {onFailure(Node node, MessageKind kind, [List arguments]),
1093 whenResolved(Node node, DartType type)}) {
1092 if (onFailure == null) { 1094 if (onFailure == null) {
1093 onFailure = (n, k, [arguments]) {}; 1095 onFailure = (n, k, [arguments]) {};
1094 } 1096 }
1095 if (whenResolved == null) { 1097 if (whenResolved == null) {
1096 whenResolved = (n, t) {}; 1098 whenResolved = (n, t) {};
1097 } 1099 }
1098 if (inClass != null) { 1100 if (scope == null) {
1099 inScope = inClass.buildScope();
1100 }
1101 if (inScope == null) {
1102 compiler.internalError('resolveTypeAnnotation: no scope specified'); 1101 compiler.internalError('resolveTypeAnnotation: no scope specified');
1103 } 1102 }
1104 return resolveTypeAnnotationInContext(inScope, node, onFailure, 1103 return resolveTypeAnnotationInContext(scope, node, onFailure,
1105 whenResolved); 1104 whenResolved);
1106 } 1105 }
1107 1106
1108 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, 1107 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node,
1109 onFailure, whenResolved) { 1108 onFailure, whenResolved) {
1110 Element element = resolveTypeName(scope, node); 1109 Element element = resolveTypeName(scope, node);
1111 DartType type; 1110 DartType type;
1112 if (element == null) { 1111 if (element == null) {
1113 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); 1112 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
1114 } else if (element.isErroneous()) { 1113 } else if (element.isErroneous()) {
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 argument.element.enclosingElement); 1952 argument.element.enclosingElement);
1954 } else if (argument is InterfaceType) { 1953 } else if (argument is InterfaceType) {
1955 InterfaceType type = argument; 1954 InterfaceType type = argument;
1956 type.arguments.forEach((DartType argument) { 1955 type.arguments.forEach((DartType argument) {
1957 analyzeTypeArgument(type, argument); 1956 analyzeTypeArgument(type, argument);
1958 }); 1957 });
1959 } 1958 }
1960 } 1959 }
1961 1960
1962 DartType resolveTypeAnnotation(TypeAnnotation node) { 1961 DartType resolveTypeAnnotation(TypeAnnotation node) {
1962 void checkAndUseType(TypeAnnotation annotation, DartType type) {
ahe 2012/10/23 16:17:13 Add TODO to say we should get rid of this.
Johnni Winther 2012/10/24 14:28:35 Done.
1963 useType(annotation, type);
1964 if (type != null &&
1965 identical(type.kind, TypeKind.TYPE_VARIABLE) &&
1966 enclosingElement.isInStaticMember()) {
1967 error(annotation, MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1968 [type]);
1969 }
1970 }
1971
1963 Function report = typeRequired ? error : warning; 1972 Function report = typeRequired ? error : warning;
1964 DartType type = typeResolver.resolveTypeAnnotation(node, inScope: scope, 1973 DartType type = typeResolver.resolveTypeAnnotation(
1965 onFailure: report, 1974 node, scope, onFailure: report, whenResolved: checkAndUseType);
1966 whenResolved: useType);
1967 if (type == null) return null; 1975 if (type == null) return null;
1968 if (inCheckContext) { 1976 if (inCheckContext) {
1969 compiler.enqueuer.resolution.registerIsCheck(type); 1977 compiler.enqueuer.resolution.registerIsCheck(type);
1970 } 1978 }
1971 if (typeRequired || inCheckContext) { 1979 if (typeRequired || inCheckContext) {
1972 if (type is InterfaceType) { 1980 if (type is InterfaceType) {
1973 InterfaceType itf = type; 1981 InterfaceType itf = type;
1974 itf.arguments.forEach((DartType argument) { 1982 itf.arguments.forEach((DartType argument) {
1975 analyzeTypeArgument(type, argument); 1983 analyzeTypeArgument(type, argument);
1976 }); 1984 });
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 SourceString typeName = typeVariable.name; 2314 SourceString typeName = typeVariable.name;
2307 TypeVariable typeNode = nodeLink.head; 2315 TypeVariable typeNode = nodeLink.head;
2308 if (nameSet.contains(typeName)) { 2316 if (nameSet.contains(typeName)) {
2309 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); 2317 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]);
2310 } 2318 }
2311 nameSet.add(typeName); 2319 nameSet.add(typeName);
2312 2320
2313 TypeVariableElement variableElement = typeVariable.element; 2321 TypeVariableElement variableElement = typeVariable.element;
2314 if (typeNode.bound != null) { 2322 if (typeNode.bound != null) {
2315 DartType boundType = typeResolver.resolveTypeAnnotation( 2323 DartType boundType = typeResolver.resolveTypeAnnotation(
2316 typeNode.bound, inScope: scope, onFailure: warning); 2324 typeNode.bound, scope, onFailure: warning);
2317 if (boundType != null && boundType.element == variableElement) { 2325 if (boundType != null && boundType.element == variableElement) {
2318 // TODO(johnniwinther): Check for more general cycles, like 2326 // TODO(johnniwinther): Check for more general cycles, like
2319 // [: <A extends B, B extends C, C extends B> :]. 2327 // [: <A extends B, B extends C, C extends B> :].
2320 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, 2328 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE,
2321 [variableElement.name]); 2329 [variableElement.name]);
2322 } else if (boundType != null) { 2330 } else if (boundType != null) {
2323 variableElement.bound = boundType; 2331 variableElement.bound = boundType;
2324 } else { 2332 } else {
2325 // TODO(johnniwinther): Should be an erroneous type. 2333 // TODO(johnniwinther): Should be an erroneous type.
2326 variableElement.bound = compiler.objectClass.computeType(compiler); 2334 variableElement.bound = compiler.objectClass.computeType(compiler);
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
2959 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); 2967 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]);
2960 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { 2968 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) {
2961 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); 2969 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]);
2962 } else if (!identical(e.kind, ElementKind.CLASS) 2970 } else if (!identical(e.kind, ElementKind.CLASS)
2963 && !identical(e.kind, ElementKind.PREFIX)) { 2971 && !identical(e.kind, ElementKind.PREFIX)) {
2964 error(node, MessageKind.NOT_A_TYPE, [name]); 2972 error(node, MessageKind.NOT_A_TYPE, [name]);
2965 } 2973 }
2966 return e; 2974 return e;
2967 } 2975 }
2968 } 2976 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698