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

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

Issue 1142853002: Handle type parameters correctly when generating hints (issue 23243) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 engine.resolver.element_resolver; 5 library engine.resolver.element_resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'element.dart'; 10 import 'element.dart';
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 bool generatedWithTypePropagation = false; 644 bool generatedWithTypePropagation = false;
645 if (_enableHints && errorCode == null && staticElement == null) { 645 if (_enableHints && errorCode == null && staticElement == null) {
646 // The method lookup may have failed because there were multiple 646 // The method lookup may have failed because there were multiple
647 // incompatible choices. In this case we don't want to generate a hint. 647 // incompatible choices. In this case we don't want to generate a hint.
648 errorCode = _checkForInvocationError(target, false, propagatedElement); 648 errorCode = _checkForInvocationError(target, false, propagatedElement);
649 if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { 649 if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) {
650 ClassElement classElementContext = null; 650 ClassElement classElementContext = null;
651 if (target == null) { 651 if (target == null) {
652 classElementContext = _resolver.enclosingClass; 652 classElementContext = _resolver.enclosingClass;
653 } else { 653 } else {
654 DartType type = target.bestType; 654 DartType type = _getBestType(target);
655 if (type != null) { 655 if (type != null) {
656 if (type.element is ClassElement) { 656 if (type.element is ClassElement) {
657 classElementContext = type.element as ClassElement; 657 classElementContext = type.element as ClassElement;
658 } 658 }
659 } 659 }
660 } 660 }
661 if (classElementContext != null) { 661 if (classElementContext != null) {
662 _subtypeManager.ensureLibraryVisited(_definingLibrary); 662 _subtypeManager.ensureLibraryVisited(_definingLibrary);
663 HashSet<ClassElement> subtypeElements = 663 HashSet<ClassElement> subtypeElements =
664 _subtypeManager.computeAllSubtypes(classElementContext); 664 _subtypeManager.computeAllSubtypes(classElementContext);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 1183 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
1184 } 1184 }
1185 } else { 1185 } else {
1186 DartType targetType; 1186 DartType targetType;
1187 if (useStaticContext) { 1187 if (useStaticContext) {
1188 targetType = _getStaticType(target); 1188 targetType = _getStaticType(target);
1189 } else { 1189 } else {
1190 // Compute and use the propagated type, if it is null, then it may 1190 // Compute and use the propagated type, if it is null, then it may
1191 // be the case that static type is some type, in which the static 1191 // be the case that static type is some type, in which the static
1192 // type should be used. 1192 // type should be used.
1193 targetType = target.bestType; 1193 targetType = _getBestType(target);
1194 } 1194 }
1195 if (targetType == null) { 1195 if (targetType == null) {
1196 return StaticTypeWarningCode.UNDEFINED_FUNCTION; 1196 return StaticTypeWarningCode.UNDEFINED_FUNCTION;
1197 } else if (!targetType.isDynamic && !targetType.isBottom) { 1197 } else if (!targetType.isDynamic && !targetType.isBottom) {
1198 // Proxy-conditional warning, based on state of 1198 // Proxy-conditional warning, based on state of
1199 // targetType.getElement() 1199 // targetType.getElement()
1200 return StaticTypeWarningCode.UNDEFINED_METHOD; 1200 return StaticTypeWarningCode.UNDEFINED_METHOD;
1201 } 1201 }
1202 } 1202 }
1203 } 1203 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 } else if (operatorType == sc.TokenType.MINUS_MINUS) { 1385 } else if (operatorType == sc.TokenType.MINUS_MINUS) {
1386 return sc.TokenType.MINUS.lexeme; 1386 return sc.TokenType.MINUS.lexeme;
1387 } else if (operatorType == sc.TokenType.MINUS) { 1387 } else if (operatorType == sc.TokenType.MINUS) {
1388 return "unary-"; 1388 return "unary-";
1389 } else { 1389 } else {
1390 return operator.lexeme; 1390 return operator.lexeme;
1391 } 1391 }
1392 } 1392 }
1393 1393
1394 /** 1394 /**
1395 * Return the best type of the given [expression] that is to be used for
1396 * type analysis.
1397 */
1398 DartType _getBestType(Expression expression) {
1399 DartType bestType = _resolveTypeParameter(expression.bestType);
1400 if (bestType is FunctionType) {
1401 //
1402 // All function types are subtypes of 'Function', which is itself a
1403 // subclass of 'Object'.
1404 //
1405 bestType = _resolver.typeProvider.functionType;
1406 }
1407 return bestType;
1408 }
1409
1410 /**
1395 * Return the propagated type of the given [expression] that is to be used for 1411 * Return the propagated type of the given [expression] that is to be used for
1396 * type analysis. 1412 * type analysis.
1397 */ 1413 */
1398 DartType _getPropagatedType(Expression expression) { 1414 DartType _getPropagatedType(Expression expression) {
1399 DartType propagatedType = _resolveTypeParameter(expression.propagatedType); 1415 DartType propagatedType = _resolveTypeParameter(expression.propagatedType);
1400 if (propagatedType is FunctionType) { 1416 if (propagatedType is FunctionType) {
1401 // 1417 //
1402 // All function types are subtypes of 'Function', which is itself a 1418 // All function types are subtypes of 'Function', which is itself a
1403 // subclass of 'Object'. 1419 // subclass of 'Object'.
1404 // 1420 //
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 2792
2777 @override 2793 @override
2778 Element get staticElement => null; 2794 Element get staticElement => null;
2779 2795
2780 @override 2796 @override
2781 accept(AstVisitor visitor) => null; 2797 accept(AstVisitor visitor) => null;
2782 2798
2783 @override 2799 @override
2784 void visitChildren(AstVisitor visitor) {} 2800 void visitChildren(AstVisitor visitor) {}
2785 } 2801 }
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