mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
![Nicholas Shahan](/assets/img/avatar_default.png)
Change-Id: I2a35de7f79b8d768cdd0144b3bf5de87fa929942 Issue: https://github.com/dart-lang/sdk/issues/42107 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154301 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com>
52 lines
1.4 KiB
Dart
52 lines
1.4 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.
|
|
|
|
// SharedOptions=--enable-experiment=variance
|
|
|
|
// Tests the emission of explicit variance modifiers.
|
|
|
|
import 'dart:_runtime'
|
|
show getGenericArgVariances, Variance, typeRep;
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
class A<in T> {}
|
|
|
|
class B<out T> {}
|
|
|
|
class C<inout T> {}
|
|
|
|
class D<T> {}
|
|
|
|
class E<inout X, out Y, in Z> {}
|
|
|
|
mixin F<in T> {}
|
|
|
|
class G<inout T> = Object with F<T>;
|
|
|
|
List? getVariances(Object type) {
|
|
// TODO(nshahan) Revisit when we decide if getGenericArgVariances will handle
|
|
// legacy and nullable wrappers.
|
|
return getGenericArgVariances(type);
|
|
}
|
|
|
|
main() {
|
|
Expect.listEquals([Variance.contravariant], getVariances(typeRep<A>())!);
|
|
|
|
Expect.listEquals([Variance.covariant], getVariances(typeRep<B>())!);
|
|
|
|
Expect.listEquals([Variance.invariant], getVariances(typeRep<C>())!);
|
|
|
|
// Implicit variance is not emitted into the generated code.
|
|
Expect.isNull(getVariances(typeRep<D>()));
|
|
|
|
Expect.listEquals(
|
|
[Variance.invariant, Variance.covariant, Variance.contravariant],
|
|
getVariances(typeRep<E>())!);
|
|
|
|
Expect.listEquals([Variance.contravariant], getVariances(typeRep<F>())!);
|
|
|
|
Expect.listEquals([Variance.invariant], getVariances(typeRep<G>())!);
|
|
}
|