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

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

Issue 2998873002: fix #30427, casting tearoffs to the wrong type (Closed)
Patch Set: Created 3 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 | tests/language_strong/covariant_subtyping_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 568a59856d7493306e0db16ce98b1e570b9bb27a..e09f6af3f3b8fec50d6c82c46e312c3ac9826b7d 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -913,13 +913,20 @@ class CodeChecker extends RecursiveAstVisitor {
var expectedType = member.returnType;
Jennifer Messerly 2017/08/11 22:06:07 If we wanted to fix other covariant tearoffs by ca
if (!rules.isSubtypeOf(memberLowerBound.returnType, expectedType)) {
- if (node is MethodInvocation && member is! MethodElement) {
- // If `o.m` is not a method, we need to cast `o.m` before the call:
- // `(o.m as expectedType)(args)`.
+ var isMethod = member is MethodElement;
+ var isCall = node is MethodInvocation;
+
+ if (isMethod && !isCall) {
+ // If `o.m` is a method tearoff, cast to the method type.
+ setImplicitCast(node, member.type);
+ } else if (!isMethod && isCall) {
+ // If `o.g()` is calling a field/getter `g`, we need to cast `o.g`
+ // before the call: `(o.g as expectedType)(args)`.
// This cannot be represented by an `as` node without changing the
// Dart AST structure, so we record it as a special cast.
setImplicitOperationCast(node, expectedType);
} else {
+ // For method calls `o.m()` or getters `o.g`, simply cast the result.
setImplicitCast(node, expectedType);
}
_hasImplicitCasts = true;
« no previous file with comments | « no previous file | tests/language_strong/covariant_subtyping_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698