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

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, 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 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 } 1080 }
1080 } else { 1081 } else {
1081 return scope.lookup(typeName.source); 1082 return scope.lookup(typeName.source);
1082 } 1083 }
1083 } 1084 }
1084 1085
1085 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean 1086 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean
1086 // flags instead of closures. 1087 // flags instead of closures.
1087 // TODO(johnniwinther): Should never return [null] but instead an erroneous 1088 // TODO(johnniwinther): Should never return [null] but instead an erroneous
1088 // type. 1089 // type.
1089 DartType resolveTypeAnnotation(TypeAnnotation node, 1090 DartType resolveTypeAnnotation(
1090 {Scope inScope, ClassElement inClass, 1091 TypeAnnotation node,
1091 onFailure(Node, MessageKind, [List arguments]), 1092 Scope scope,
1092 whenResolved(Node, Type)}) { 1093 {onFailure(Node node, MessageKind kind, [List arguments]),
1094 whenResolved(Node node, DartType type)}) {
1093 if (onFailure == null) { 1095 if (onFailure == null) {
1094 onFailure = (n, k, [arguments]) {}; 1096 onFailure = (n, k, [arguments]) {};
1095 } 1097 }
1096 if (whenResolved == null) { 1098 if (whenResolved == null) {
1097 whenResolved = (n, t) {}; 1099 whenResolved = (n, t) {};
1098 } 1100 }
1099 if (inClass != null) { 1101 if (scope == null) {
1100 inScope = inClass.buildScope();
1101 }
1102 if (inScope == null) {
1103 compiler.internalError('resolveTypeAnnotation: no scope specified'); 1102 compiler.internalError('resolveTypeAnnotation: no scope specified');
1104 } 1103 }
1105 return resolveTypeAnnotationInContext(inScope, node, onFailure, 1104 return resolveTypeAnnotationInContext(scope, node, onFailure,
1106 whenResolved); 1105 whenResolved);
1107 } 1106 }
1108 1107
1109 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, 1108 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node,
1110 onFailure, whenResolved) { 1109 onFailure, whenResolved) {
1111 Element element = resolveTypeName(scope, node); 1110 Element element = resolveTypeName(scope, node);
1112 DartType type; 1111 DartType type;
1113 if (element == null) { 1112 if (element == null) {
1114 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); 1113 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
1115 } else if (element.isErroneous()) { 1114 } else if (element.isErroneous()) {
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 argument.element.enclosingElement); 1951 argument.element.enclosingElement);
1953 } else if (argument is InterfaceType) { 1952 } else if (argument is InterfaceType) {
1954 InterfaceType type = argument; 1953 InterfaceType type = argument;
1955 type.arguments.forEach((DartType argument) { 1954 type.arguments.forEach((DartType argument) {
1956 analyzeTypeArgument(type, argument); 1955 analyzeTypeArgument(type, argument);
1957 }); 1956 });
1958 } 1957 }
1959 } 1958 }
1960 1959
1961 DartType resolveTypeAnnotation(TypeAnnotation node) { 1960 DartType resolveTypeAnnotation(TypeAnnotation node) {
1961 void checkAndUseType(TypeAnnotation annotation, DartType type) {
1962 useType(annotation, type);
1963 if (type != null &&
1964 identical(type.kind, TypeKind.TYPE_VARIABLE) &&
1965 enclosingElement.isInStaticMember()) {
1966 error(annotation, MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1967 [type]);
1968 }
1969 }
1970
1962 Function report = typeRequired ? error : warning; 1971 Function report = typeRequired ? error : warning;
1963 DartType type = typeResolver.resolveTypeAnnotation(node, inScope: scope, 1972 DartType type = typeResolver.resolveTypeAnnotation(
1964 onFailure: report, 1973 node, scope, onFailure: report, whenResolved: checkAndUseType);
1965 whenResolved: useType);
1966 if (type == null) return null; 1974 if (type == null) return null;
1967 if (inCheckContext) { 1975 if (inCheckContext) {
1968 compiler.enqueuer.resolution.registerIsCheck(type); 1976 compiler.enqueuer.resolution.registerIsCheck(type);
1969 } 1977 }
1970 if (typeRequired || inCheckContext) { 1978 if (typeRequired || inCheckContext) {
1971 if (type is InterfaceType) { 1979 if (type is InterfaceType) {
1972 InterfaceType itf = type; 1980 InterfaceType itf = type;
1973 itf.arguments.forEach((DartType argument) { 1981 itf.arguments.forEach((DartType argument) {
1974 analyzeTypeArgument(type, argument); 1982 analyzeTypeArgument(type, argument);
1975 }); 1983 });
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 SourceString typeName = typeVariable.name; 2313 SourceString typeName = typeVariable.name;
2306 TypeVariable typeNode = nodeLink.head; 2314 TypeVariable typeNode = nodeLink.head;
2307 if (nameSet.contains(typeName)) { 2315 if (nameSet.contains(typeName)) {
2308 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); 2316 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]);
2309 } 2317 }
2310 nameSet.add(typeName); 2318 nameSet.add(typeName);
2311 2319
2312 TypeVariableElement variableElement = typeVariable.element; 2320 TypeVariableElement variableElement = typeVariable.element;
2313 if (typeNode.bound != null) { 2321 if (typeNode.bound != null) {
2314 DartType boundType = typeResolver.resolveTypeAnnotation( 2322 DartType boundType = typeResolver.resolveTypeAnnotation(
2315 typeNode.bound, inScope: scope, onFailure: warning); 2323 typeNode.bound, scope, onFailure: warning);
2316 if (boundType != null && boundType.element == variableElement) { 2324 if (boundType != null && boundType.element == variableElement) {
2317 // TODO(johnniwinther): Check for more general cycles, like 2325 // TODO(johnniwinther): Check for more general cycles, like
2318 // [: <A extends B, B extends C, C extends B> :]. 2326 // [: <A extends B, B extends C, C extends B> :].
2319 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, 2327 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE,
2320 [variableElement.name]); 2328 [variableElement.name]);
2321 } else if (boundType != null) { 2329 } else if (boundType != null) {
2322 variableElement.bound = boundType; 2330 variableElement.bound = boundType;
2323 } else { 2331 } else {
2324 // TODO(johnniwinther): Should be an erroneous type. 2332 // TODO(johnniwinther): Should be an erroneous type.
2325 variableElement.bound = compiler.objectClass.computeType(compiler); 2333 variableElement.bound = compiler.objectClass.computeType(compiler);
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
3190 return result; 3198 return result;
3191 } 3199 }
3192 Element lookup(SourceString name) => localLookup(name); 3200 Element lookup(SourceString name) => localLookup(name);
3193 Element lexicalLookup(SourceString name) => localLookup(name); 3201 Element lexicalLookup(SourceString name) => localLookup(name);
3194 3202
3195 Element add(Element newElement) { 3203 Element add(Element newElement) {
3196 throw "Cannot add an element in a patch library scope"; 3204 throw "Cannot add an element in a patch library scope";
3197 } 3205 }
3198 String toString() => 'PatchLibraryScope($origin,$patch)'; 3206 String toString() => 'PatchLibraryScope($origin,$patch)';
3199 } 3207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698