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

Unified Diff: tests/language_2/covariant_subtyping_with_substitution_test.dart

Issue 2994373002: Add a test to demonstrate issue #30461 (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_2/language_2_analyzer.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language_2/covariant_subtyping_with_substitution_test.dart
diff --git a/tests/language_2/covariant_subtyping_with_substitution_test.dart b/tests/language_2/covariant_subtyping_with_substitution_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2160f8467f3e2d179fef0dc2c43dd6c26e87c8dc
--- /dev/null
+++ b/tests/language_2/covariant_subtyping_with_substitution_test.dart
@@ -0,0 +1,39 @@
+// Copyright (c) 2017, 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.
+import 'package:expect/expect.dart';
+
+typedef F<T>(T x);
+
+class B<T> {
+ void f(F<T> x) {}
+}
+
+abstract class I<U> {
+ void f(U x);
+}
+
+class C<V> extends B<V> implements I<F<V>> {}
+
+void acceptsObject(Object o) {}
+
+void acceptsNum(num n) {}
+
+bool isTypeError(e) => e is TypeError;
+
+void g(I<F<num>> i) {
+ i.f(acceptsObject);
+ // i.f has static type (F<num>)->void, or ((num)->void)->void. Which means we
+ // are statically allowed to pass acceptsNum to it. However, if i's runtime
+ // type is C<Object>, then it extends B<Object>, so its f function requires
+ // its argument to be F<Object>. This means that passing acceptsNum to f
+ // would violate soundness (since acceptsNum has type F<num>, and F<num> is a
+ // supertype of F<Object>). So we expect a type error here.
+ Expect.throws(() {
+ i.f(acceptsNum);
+ }, isTypeError);
+}
+
+void main() {
+ g(new C<Object>());
+}
« no previous file with comments | « no previous file | tests/language_2/language_2_analyzer.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698