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

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: Status updated Created 8 years, 1 month 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 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 // the error message below. 326 // the error message below.
327 error(node, 327 error(node,
328 MessageKind.CANNOT_FIND_CONSTRUCTOR2, 328 MessageKind.CANNOT_FIND_CONSTRUCTOR2,
329 [selector.name, defaultClass.name]); 329 [selector.name, defaultClass.name]);
330 } 330 }
331 } 331 }
332 332
333 TreeElements resolveField(VariableElement element) { 333 TreeElements resolveField(VariableElement element) {
334 Node tree = element.parseNode(compiler); 334 Node tree = element.parseNode(compiler);
335 if(element.modifiers.isStatic() && element.variables.isTopLevel()) { 335 if(element.modifiers.isStatic() && element.variables.isTopLevel()) {
336 error(element.modifiers.getStatic(), MessageKind.TOP_LEVEL_VARIABLE_DECLAR ED_STATIC); 336 error(element.modifiers.getStatic(),
337 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC);
337 } 338 }
338 ResolverVisitor visitor = visitorFor(element); 339 ResolverVisitor visitor = visitorFor(element);
339 initializerDo(tree, visitor.visit); 340 initializerDo(tree, visitor.visit);
340 return visitor.mapping; 341 return visitor.mapping;
341 } 342 }
342 343
343 TreeElements resolveParameter(Element element) { 344 TreeElements resolveParameter(Element element) {
344 Node tree = element.parseNode(compiler); 345 Node tree = element.parseNode(compiler);
345 ResolverVisitor visitor = visitorFor(element.enclosingElement); 346 ResolverVisitor visitor = visitorFor(element.enclosingElement);
346 initializerDo(tree, visitor.visit); 347 initializerDo(tree, visitor.visit);
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 } 1052 }
1052 } else { 1053 } else {
1053 return scope.lookup(typeName.source); 1054 return scope.lookup(typeName.source);
1054 } 1055 }
1055 } 1056 }
1056 1057
1057 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean 1058 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean
1058 // flags instead of closures. 1059 // flags instead of closures.
1059 // TODO(johnniwinther): Should never return [null] but instead an erroneous 1060 // TODO(johnniwinther): Should never return [null] but instead an erroneous
1060 // type. 1061 // type.
1061 DartType resolveTypeAnnotation(TypeAnnotation node, 1062 DartType resolveTypeAnnotation(
1062 {Scope inScope, ClassElement inClass, 1063 TypeAnnotation node,
1063 onFailure(Node, MessageKind, [List arguments]), 1064 Scope scope,
1064 whenResolved(Node, Type)}) { 1065 {onFailure(Node node, MessageKind kind, [List arguments]),
1066 whenResolved(Node node, DartType type)}) {
1065 if (onFailure == null) { 1067 if (onFailure == null) {
1066 onFailure = (n, k, [arguments]) {}; 1068 onFailure = (n, k, [arguments]) {};
1067 } 1069 }
1068 if (whenResolved == null) { 1070 if (whenResolved == null) {
1069 whenResolved = (n, t) {}; 1071 whenResolved = (n, t) {};
1070 } 1072 }
1071 if (inClass != null) { 1073 if (scope == null) {
1072 inScope = inClass.buildScope();
1073 }
1074 if (inScope == null) {
1075 compiler.internalError('resolveTypeAnnotation: no scope specified'); 1074 compiler.internalError('resolveTypeAnnotation: no scope specified');
1076 } 1075 }
1077 return resolveTypeAnnotationInContext(inScope, node, onFailure, 1076 return resolveTypeAnnotationInContext(scope, node, onFailure,
1078 whenResolved); 1077 whenResolved);
1079 } 1078 }
1080 1079
1081 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, 1080 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node,
1082 onFailure, whenResolved) { 1081 onFailure, whenResolved) {
1083 Element element = resolveTypeName(scope, node); 1082 Element element = resolveTypeName(scope, node);
1084 DartType type; 1083 DartType type;
1085 if (element == null) { 1084 if (element == null) {
1086 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); 1085 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
1087 } else if (element.isErroneous()) { 1086 } else if (element.isErroneous()) {
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 argument.element.enclosingElement); 1973 argument.element.enclosingElement);
1975 } else if (argument is InterfaceType) { 1974 } else if (argument is InterfaceType) {
1976 InterfaceType type = argument; 1975 InterfaceType type = argument;
1977 type.arguments.forEach((DartType argument) { 1976 type.arguments.forEach((DartType argument) {
1978 analyzeTypeArgument(type, argument); 1977 analyzeTypeArgument(type, argument);
1979 }); 1978 });
1980 } 1979 }
1981 } 1980 }
1982 1981
1983 DartType resolveTypeAnnotation(TypeAnnotation node) { 1982 DartType resolveTypeAnnotation(TypeAnnotation node) {
1983 // TODO(johnniwinther): Remove this together with the named arguments
1984 // on [TypeResolver.resolveTypeAnnotation].
1985 void checkAndUseType(TypeAnnotation annotation, DartType type) {
1986 useType(annotation, type);
1987 if (type != null &&
1988 identical(type.kind, TypeKind.TYPE_VARIABLE) &&
1989 enclosingElement.isInStaticMember()) {
1990 warning(annotation, MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1991 [type]);
1992 }
1993 }
1994
1984 Function report = typeRequired ? error : warning; 1995 Function report = typeRequired ? error : warning;
1985 DartType type = typeResolver.resolveTypeAnnotation(node, inScope: scope, 1996 DartType type = typeResolver.resolveTypeAnnotation(
1986 onFailure: report, 1997 node, scope, onFailure: report, whenResolved: checkAndUseType);
1987 whenResolved: useType);
1988 if (type == null) return null; 1998 if (type == null) return null;
1989 if (inCheckContext) { 1999 if (inCheckContext) {
1990 compiler.enqueuer.resolution.registerIsCheck(type); 2000 compiler.enqueuer.resolution.registerIsCheck(type);
1991 } 2001 }
1992 if (typeRequired || inCheckContext) { 2002 if (typeRequired || inCheckContext) {
1993 if (type is InterfaceType) { 2003 if (type is InterfaceType) {
1994 InterfaceType itf = type; 2004 InterfaceType itf = type;
1995 itf.arguments.forEach((DartType argument) { 2005 itf.arguments.forEach((DartType argument) {
1996 analyzeTypeArgument(type, argument); 2006 analyzeTypeArgument(type, argument);
1997 }); 2007 });
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 SourceString typeName = typeVariable.name; 2352 SourceString typeName = typeVariable.name;
2343 TypeVariable typeNode = nodeLink.head; 2353 TypeVariable typeNode = nodeLink.head;
2344 if (nameSet.contains(typeName)) { 2354 if (nameSet.contains(typeName)) {
2345 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); 2355 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]);
2346 } 2356 }
2347 nameSet.add(typeName); 2357 nameSet.add(typeName);
2348 2358
2349 TypeVariableElement variableElement = typeVariable.element; 2359 TypeVariableElement variableElement = typeVariable.element;
2350 if (typeNode.bound != null) { 2360 if (typeNode.bound != null) {
2351 DartType boundType = typeResolver.resolveTypeAnnotation( 2361 DartType boundType = typeResolver.resolveTypeAnnotation(
2352 typeNode.bound, inScope: scope, onFailure: warning); 2362 typeNode.bound, scope, onFailure: warning);
2353 if (boundType != null && boundType.element == variableElement) { 2363 if (boundType != null && boundType.element == variableElement) {
2354 // TODO(johnniwinther): Check for more general cycles, like 2364 // TODO(johnniwinther): Check for more general cycles, like
2355 // [: <A extends B, B extends C, C extends B> :]. 2365 // [: <A extends B, B extends C, C extends B> :].
2356 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, 2366 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE,
2357 [variableElement.name]); 2367 [variableElement.name]);
2358 } else if (boundType != null) { 2368 } else if (boundType != null) {
2359 variableElement.bound = boundType; 2369 variableElement.bound = boundType;
2360 } else { 2370 } else {
2361 // TODO(johnniwinther): Should be an erroneous type. 2371 // TODO(johnniwinther): Should be an erroneous type.
2362 variableElement.bound = compiler.objectClass.computeType(compiler); 2372 variableElement.bound = compiler.objectClass.computeType(compiler);
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
2996 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); 3006 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]);
2997 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { 3007 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) {
2998 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); 3008 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]);
2999 } else if (!identical(e.kind, ElementKind.CLASS) 3009 } else if (!identical(e.kind, ElementKind.CLASS)
3000 && !identical(e.kind, ElementKind.PREFIX)) { 3010 && !identical(e.kind, ElementKind.PREFIX)) {
3001 error(node, MessageKind.NOT_A_TYPE, [name]); 3011 error(node, MessageKind.NOT_A_TYPE, [name]);
3002 } 3012 }
3003 return e; 3013 return e;
3004 } 3014 }
3005 } 3015 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698