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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1702713003: Don't set DynamicElementImpl as staticElement for unresolved types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Document _setElement. Created 4 years, 10 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 11549 matching lines...) Expand 10 before | Expand all | Expand 10 after
11560 } else { 11560 } else {
11561 reportErrorForNode( 11561 reportErrorForNode(
11562 StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]); 11562 StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]);
11563 } 11563 }
11564 elementValid = false; 11564 elementValid = false;
11565 } 11565 }
11566 if (!elementValid) { 11566 if (!elementValid) {
11567 if (element is MultiplyDefinedElement) { 11567 if (element is MultiplyDefinedElement) {
11568 _setElement(typeName, element); 11568 _setElement(typeName, element);
11569 } else { 11569 } else {
11570 _setElement(typeName, _dynamicType.element); 11570 _setElement(typeName, null);
11571 } 11571 }
11572 typeName.staticType = _undefinedType; 11572 typeName.staticType = _undefinedType;
11573 node.type = _undefinedType; 11573 node.type = _undefinedType;
11574 return null; 11574 return null;
11575 } 11575 }
11576 DartType type = null; 11576 DartType type = null;
11577 if (element is ClassElement) { 11577 if (element is ClassElement) {
11578 _setElement(typeName, element); 11578 _setElement(typeName, element);
11579 type = element.type; 11579 type = element.type;
11580 } else if (element is FunctionTypeAliasElement) { 11580 } else if (element is FunctionTypeAliasElement) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
11625 if (parent is ExtendsClause || 11625 if (parent is ExtendsClause ||
11626 parent is ImplementsClause || 11626 parent is ImplementsClause ||
11627 parent is WithClause || 11627 parent is WithClause ||
11628 parent is ClassTypeAlias) { 11628 parent is ClassTypeAlias) {
11629 // Ignored. The error will be reported elsewhere. 11629 // Ignored. The error will be reported elsewhere.
11630 } else { 11630 } else {
11631 reportErrorForNode( 11631 reportErrorForNode(
11632 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); 11632 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]);
11633 } 11633 }
11634 } 11634 }
11635 _setElement(typeName, _dynamicType.element); 11635 _setElement(typeName, null);
11636 typeName.staticType = _dynamicType; 11636 typeName.staticType = _dynamicType;
11637 node.type = _dynamicType; 11637 node.type = _dynamicType;
11638 return null; 11638 return null;
11639 } 11639 }
11640 if (argumentList != null) { 11640 if (argumentList != null) {
11641 NodeList<TypeName> arguments = argumentList.arguments; 11641 NodeList<TypeName> arguments = argumentList.arguments;
11642 int argumentCount = arguments.length; 11642 int argumentCount = arguments.length;
11643 List<DartType> parameters = _getTypeParameters(type); 11643 List<DartType> parameters = _getTypeParameters(type);
11644 int parameterCount = parameters.length; 11644 int parameterCount = parameters.length;
11645 List<DartType> typeArguments = new List<DartType>(parameterCount); 11645 List<DartType> typeArguments = new List<DartType>(parameterCount);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
12127 for (TypeName typeName in typeNames) { 12127 for (TypeName typeName in typeNames) {
12128 InterfaceType type = 12128 InterfaceType type =
12129 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError); 12129 _resolveType(typeName, nonTypeError, enumTypeError, dynamicTypeError);
12130 if (type != null) { 12130 if (type != null) {
12131 types.add(type); 12131 types.add(type);
12132 } 12132 }
12133 } 12133 }
12134 return types; 12134 return types;
12135 } 12135 }
12136 12136
12137 /**
12138 * If the given [element] is not `null`, set `staticElement` of the
12139 * [typeName] to it. If the [typeName] is a prefixed identifier, and the
12140 * prefix can be resolved to a not `null` element, set also the
12141 * `staticElement` of the prefix.
12142 */
12137 void _setElement(Identifier typeName, Element element) { 12143 void _setElement(Identifier typeName, Element element) {
12138 if (element != null) { 12144 if (typeName is SimpleIdentifier) {
12139 if (typeName is SimpleIdentifier) { 12145 if (element != null) {
12140 typeName.staticElement = element; 12146 typeName.staticElement = element;
12141 } else if (typeName is PrefixedIdentifier) { 12147 }
12142 PrefixedIdentifier identifier = typeName; 12148 } else if (typeName is PrefixedIdentifier) {
12143 identifier.identifier.staticElement = element; 12149 if (element != null) {
12144 SimpleIdentifier prefix = identifier.prefix; 12150 typeName.identifier.staticElement = element;
12145 Element prefixElement = nameScope.lookup(prefix, definingLibrary); 12151 }
12146 if (prefixElement != null) { 12152 SimpleIdentifier prefix = typeName.prefix;
12147 prefix.staticElement = prefixElement; 12153 Element prefixElement = nameScope.lookup(prefix, definingLibrary);
12148 } 12154 if (prefixElement != null) {
12155 prefix.staticElement = prefixElement;
12149 } 12156 }
12150 } 12157 }
12151 } 12158 }
12152 12159
12153 /** 12160 /**
12154 * Given a parameter element, create a function type based on the given return type and parameter 12161 * Given a parameter element, create a function type based on the given return type and parameter
12155 * list and associate the created type with the element. 12162 * list and associate the created type with the element.
12156 * 12163 *
12157 * @param element the parameter element whose type is to be set 12164 * @param element the parameter element whose type is to be set
12158 * @param returnType the (possibly `null`) return type of the function 12165 * @param returnType the (possibly `null`) return type of the function
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
12734 nonFields.add(node); 12741 nonFields.add(node);
12735 return null; 12742 return null;
12736 } 12743 }
12737 12744
12738 @override 12745 @override
12739 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 12746 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
12740 12747
12741 @override 12748 @override
12742 Object visitWithClause(WithClause node) => null; 12749 Object visitWithClause(WithClause node) => null;
12743 } 12750 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698