Files
sdk/tests/language_2/variance/variance_in_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

50 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 subclass usage for the `in` variance modifier.
// SharedOptions=--enable-experiment=variance
typedef CovFunction<T> = T Function();
typedef ContraFunction<T> = void Function(T);
class Covariant<out T> {}
class Contravariant<in T> {}
mixin MContravariant<in T> {}
class A<in T> extends Contravariant<T> {}
class B<in T> implements Contravariant<T> {}
class C<in T> with MContravariant<T> {}
class D<in T> extends Covariant<Contravariant<T>> {}
class E<in T> extends Contravariant<Covariant<T>> {}
class F<in T> extends Covariant<ContraFunction<T>> {}
class G<in T> extends Covariant<ContraFunction<CovFunction<T>>> {}
class H<in T> extends Covariant<CovFunction<ContraFunction<T>>> {}
class I<in T> extends Covariant<ContraFunction<Covariant<T>>> {}
class J<in T> extends Contravariant<Contravariant<Contravariant<T>>> {}
class K<in T> = Contravariant<T> with MContravariant<T>;
class L<in T> = Covariant<Contravariant<T>> with MContravariant<T>;
class M<in T> = Contravariant<T> with MContravariant<Covariant<T>>;
main() {
A<num> a = A();
B<num> b = B();
C<num> c = C();
D<num> d = D();
E<num> e = E();
F<num> f = F();
G<num> g = G();
H<num> h = H();
I<num> i = I();
J<num> j = J();
K<num> k = K();
L<num> l = L();
M<num> m = M();
}