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

Unified Diff: pkg/kernel/testcases/input/covariant_generic.dart

Issue 2618393002: Insert covariance checks in strong mode. (Closed)
Patch Set: Merge Created 3 years, 11 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/kernel/testcases/input/covariant_generic.dart
diff --git a/pkg/kernel/testcases/input/covariant_generic.dart b/pkg/kernel/testcases/input/covariant_generic.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a0234a681ce5d20e6a1c99f836c35cb12cce921a
--- /dev/null
+++ b/pkg/kernel/testcases/input/covariant_generic.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+typedef void Callback<T>(T x);
+
+class Foo<T> {
+ final T finalField;
+ final Callback<T> callbackField;
+
+ T mutableField;
+ Callback<T> mutableCallbackField;
+
+ Foo(this.finalField, this.callbackField);
+
+ void method(T x) {}
+
+ set setter(T x) {}
+
+ void withCallback(Callback<T> callback) {
+ callback(finalField);
+ }
+}
+
+main() {
+ Foo<int> fooInt = new Foo<int>(1, (int x) {});
+
+ fooInt.method(3);
+ fooInt.setter = 3;
+ fooInt.withCallback((int x) {});
+ fooInt.withCallback((num x) {});
+ fooInt.mutableField = 3;
+ fooInt.mutableCallbackField = (int x) {};
+
+ Foo<num> fooNum = fooInt;
+ fooNum.method(3);
+ fooNum.method(2.5);
+ fooNum.setter = 3;
+ fooNum.setter = 2.5;
+ fooNum.withCallback((num x) {});
+ fooNum.mutableField = 3;
+ fooNum.mutableField = 2.5;
+ fooNum.mutableCallbackField(3);
+ fooNum.mutableCallbackField(2.5);
+ fooNum.mutableCallbackField = (num x) {};
+}

Powered by Google App Engine
This is Rietveld 408576698