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

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

Issue 2336503003: fix #25578, implement @covariant parameter overrides (Closed)
Patch Set: fix comments, format Created 4 years, 3 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 | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/lib/src/task/strong_mode.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 f47c95728b04309c6425d7732f3ab6d6b47dceb6..ac2f6ef780b889b883f68d6231aaee6cd4c62a88 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -1121,13 +1121,11 @@ class CodeChecker extends RecursiveAstVisitor {
/// applications.
class _OverrideChecker {
final StrongTypeSystemImpl rules;
- final TypeProvider _typeProvider;
final CodeChecker _checker;
_OverrideChecker(CodeChecker checker)
: _checker = checker,
- rules = checker.rules,
- _typeProvider = checker.typeProvider;
+ rules = checker.rules;
void check(ClassDeclaration node) {
if (node.element.type.isObject) return;
@@ -1409,24 +1407,8 @@ class _OverrideChecker {
concreteSubType = rules.instantiateToBounds(concreteSubType);
}
}
- concreteSubType =
- rules.typeToConcreteType(_typeProvider, concreteSubType);
- concreteBaseType =
- rules.typeToConcreteType(_typeProvider, concreteBaseType);
-
- if (!rules.isSubtypeOf(concreteSubType, concreteBaseType)) {
- // See whether non-subtype cases fit one of our common patterns:
- //
- // Common pattern 1: Inferable return type (on getters and methods)
- // class A {
- // int get foo => ...;
- // String toString() { ... }
- // }
- // class B extends A {
- // get foo => e; // no type specified.
- // toString() { ... } // no return type specified.
- // }
+ if (!rules.isOverrideSubtypeOf(concreteSubType, concreteBaseType)) {
ErrorCode errorCode;
if (errorLocation is ExtendsClause) {
errorCode = StrongModeCode.INVALID_METHOD_OVERRIDE_FROM_BASE;
@@ -1444,7 +1426,12 @@ class _OverrideChecker {
baseType
]);
}
- return true;
+
+ // If we have any covariant parameters and we're comparing against a
+ // superclass, we check all superclasses instead of stopping the search.
+ bool hasCovariant = element.parameters.any((p) => p.isCovariant);
+ bool keepSearching = hasCovariant && isSubclass;
+ return !keepSearching;
}
/// Check overrides between a class and its superclasses and mixins. For
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | pkg/analyzer/lib/src/task/strong_mode.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698