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

Unified Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 2211053002: fix #26962, invoking a known lambda is not a dynamic invoke (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix comment Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/strong/checker.dart
diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart
index c074b7938c7aec46eabdae9302f15523b0dd0659..ceaa4bfceba38a32e15e992fe379d763f8c21b48 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -21,8 +21,11 @@ import 'package:analyzer/src/generated/type_system.dart';
import 'ast_properties.dart';
-bool isKnownFunction(Expression expression) {
+bool isKnownFunction(Expression expression, {bool instanceMethods: false}) {
Element element = null;
+ if (expression is ParenthesizedExpression) {
+ expression = (expression as ParenthesizedExpression).expression;
+ }
if (expression is FunctionExpression) {
return true;
} else if (expression is PropertyAccess) {
@@ -30,10 +33,10 @@ bool isKnownFunction(Expression expression) {
} else if (expression is Identifier) {
element = expression.staticElement;
}
-// First class functions and static methods, where we know the original
-// declaration, will have an exact type, so we know a downcast will fail.
+ // First class functions and static methods, where we know the original
+ // declaration, will have an exact type, so we know a downcast will fail.
return element is FunctionElement ||
- element is MethodElement && element.isStatic;
+ element is MethodElement && (instanceMethods || element.isStatic);
}
DartType _elementType(Element e) {
@@ -936,10 +939,6 @@ class CodeChecker extends RecursiveAstVisitor {
}
}
- // Produce a coercion which coerces something of type fromT
- // to something of type toT.
- // Returns the error coercion if the types cannot be coerced
- // according to our current criteria.
DartType _getStaticType(Expression expr) {
DartType t = expr.staticType ?? DynamicTypeImpl.instance;
@@ -985,14 +984,9 @@ class CodeChecker extends RecursiveAstVisitor {
// a dynamic parameter type requires a dynamic call in general.
// However, as an optimization, if we have an original definition, we know
// dynamic is reified as Object - in this case a regular call is fine.
- if (call is SimpleIdentifier) {
- var element = call.staticElement;
- if (element is FunctionElement || element is MethodElement) {
- // An original declaration.
- return false;
- }
+ if (isKnownFunction(call, instanceMethods: true)) {
+ return false;
}
-
return rules.anyParameterType(ft, (pt) => pt.isDynamic);
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698