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

Unified Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 2336503003: fix #25578, implement @covariant parameter overrides (Closed)
Patch Set: fix for summaries, thanks Paul! 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
Index: pkg/analyzer/test/src/task/strong/checker_test.dart
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index 2cdb1bf81f7ac9cde4594225e03ebcbb0ab89b3c..5812b03f843e0bb56c709e6b9460f2783daffb42 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -499,6 +499,112 @@ void main() {
''');
}
+ void test_covariantOverride() {
+ addFile(r'''
+library meta;
+class _Covariant { const _Covariant(); }
+const Object covariant = const _Covariant();
+ ''', name: '/meta.dart');
+
+ checkFile(r'''
+import 'meta.dart';
+class C {
+ num f(num x) => x;
+}
+class D extends C {
+ int f(@covariant int x) => x;
+}
+class E extends D {
+ int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x;
+}
+class F extends E {
+ int f(@covariant int x) => x;
+}
+class G extends E implements D {}
+
+class D_error extends C {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(int x) => x;
+}
+class E_error extends D {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(@covariant double x) => 0;
+}
+class F_error extends E {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(@covariant double x) => 0;
+}
+class G_error extends E implements D {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(@covariant double x) => 0;
+}
+ ''');
+ }
+
+ void test_covariantOverride_leastUpperBound() {
+ addFile(r'''
+library meta;
+class _Covariant { const _Covariant(); }
+const Object covariant = const _Covariant();
+ ''', name: '/meta.dart');
+
+ checkFile(r'''
+import "meta.dart";
+abstract class Top {}
+abstract class Left implements Top {}
+abstract class Right implements Top {}
+abstract class Bottom implements Left, Right {}
+
+abstract class TakesLeft {
+ m(Left x);
+}
+abstract class TakesRight {
+ m(Right x);
+}
+abstract class TakesTop implements TakesLeft, TakesRight {
+ m(Top x); // works today
+}
+abstract class TakesBottom implements TakesLeft, TakesRight {
+ // LUB(Left, Right) == Top, so this is an implicit cast from Top to Bottom.
+ m(@covariant Bottom x);
+}
+ ''');
+ }
+
+ void test_covariantOverride_markerIsInherited() {
+ addFile(r'''
+library meta;
+class _Covariant { const _Covariant(); }
+const Object covariant = const _Covariant();
+ ''', name: '/meta.dart');
+
+ checkFile(r'''
+import 'meta.dart';
+class C {
+ num f(@covariant num x) => x;
+}
+class D extends C {
+ int f(int x) => x;
+}
+class E extends D {
+ int f(Object x) => /*info:DOWN_CAST_IMPLICIT*/x;
+}
+class F extends E {
+ int f(int x) => x;
+}
+class G extends E implements D {}
+
+class D_error extends C {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(String x) => 0;
+}
+class E_error extends D {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0;
+}
+class F_error extends E {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0;
+}
+class G_error extends E implements D {
+ /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0;
+}
+ ''');
+ }
+
void test_dynamicInvocation() {
checkFile('''
typedef dynamic A(dynamic x);

Powered by Google App Engine
This is Rietveld 408576698