// 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 {} class B {} class C {} class D {} class E {} mixin F {} class G = Object with F; 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())!); Expect.listEquals([Variance.covariant], getVariances(typeRep())!); Expect.listEquals([Variance.invariant], getVariances(typeRep())!); // Implicit variance is not emitted into the generated code. Expect.isNull(getVariances(typeRep())); Expect.listEquals( [Variance.invariant, Variance.covariant, Variance.contravariant], getVariances(typeRep())!); Expect.listEquals([Variance.contravariant], getVariances(typeRep())!); Expect.listEquals([Variance.invariant], getVariances(typeRep())!); }