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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/language_2/language_2_analyzer.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 import 'package:expect/expect.dart';
5
6 typedef F<T>(T x);
7
8 class B<T> {
9 void f(F<T> x) {}
10 }
11
12 abstract class I<U> {
13 void f(U x);
14 }
15
16 class C<V> extends B<V> implements I<F<V>> {}
17
18 void acceptsObject(Object o) {}
19
20 void acceptsNum(num n) {}
21
22 bool isTypeError(e) => e is TypeError;
23
24 void g(I<F<num>> i) {
25 i.f(acceptsObject);
26 // i.f has static type (F<num>)->void, or ((num)->void)->void. Which means we
27 // are statically allowed to pass acceptsNum to it. However, if i's runtime
28 // type is C<Object>, then it extends B<Object>, so its f function requires
29 // its argument to be F<Object>. This means that passing acceptsNum to f
30 // would violate soundness (since acceptsNum has type F<num>, and F<num> is a
31 // supertype of F<Object>). So we expect a type error here.
32 Expect.throws(() {
33 i.f(acceptsNum);
34 }, isTypeError);
35 }
36
37 void main() {
38 g(new C<Object>());
39 }
OLDNEW
« 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