Files
sdk/tests/language_2/variance/variance_multi_subclass_test.dart
T
Kallen Tu e3ca5ee6ba Check variance of type-parameter use in supertypes.
Tests have both correct and erroneous implementations
of variance.

Change-Id: I49dd76f42399015dd6e3f9688e598c271ce7ab1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119722
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-10-08 21:33:40 +00:00

43 lines
1.5 KiB
Dart

// Copyright (c) 2019, 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.
// Tests variance usage multiple type parameters.
// SharedOptions=--enable-experiment=variance
typedef CovFunction<T> = T Function();
typedef ContraFunction<T> = void Function(T);
class Covariant<out T> {}
class Contravariant<in T> {}
class A<in T, out U> {}
class B<in T, out U, inout V> {}
class C<inout T, in U, out V> extends A<T, V> {}
class D<inout T, in U, out V> extends B<U, V, T> {}
class E<inout T, in U, out V> extends B<T, T, T> {}
class F<inout T, in U, out V> extends A<Contravariant<V>, Contravariant<U>> {}
class G<inout T, in U, out V> extends A<Covariant<Contravariant<V>>, Contravariant<Covariant<U>>> {}
class H<inout T, in U, out V> extends B<Covariant<U>, Covariant<V>, Covariant<T>> {}
class I<inout T, in U, out V> extends A<ContraFunction<V>, ContraFunction<U>> {}
class J<inout T, in U, out V> extends A<CovFunction<ContraFunction<V>>, ContraFunction<CovFunction<U>>> {}
class K<inout T, in U, out V> extends B<CovFunction<U>, CovFunction<V>, CovFunction<T>> {}
main() {
A<num, bool> a = A();
B<num, bool, String> b = B();
C<num, bool, String> c = C();
D<num, bool, String> d = D();
E<num, bool, String> e = E();
F<num, bool, String> f = F();
G<num, bool, String> g = G();
H<num, bool, String> h = H();
I<num, bool, String> i = I();
J<num, bool, String> j = J();
K<num, bool, String> k = K();
}