#2548. Add tests for out parameter in a contrvariant position (#2555)

Add tests for out parameter in a contravariant position.
diff --git a/TypeSystem/type-variance/out_non_covariant_A01_t01.dart b/TypeSystem/type-variance/out_non_covariant_A01_t01.dart
new file mode 100644
index 0000000..74be320
--- /dev/null
+++ b/TypeSystem/type-variance/out_non_covariant_A01_t01.dart
@@ -0,0 +1,88 @@
+// Copyright (c) 2024, 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.
+
+/// @assertion Let `D` be the declaration of a class or mixin, enum or a type
+/// extension and let `X` be a type parameter declared by `D`.
+///
+/// If `X` has the variance modifier `out` then it is a compile-time error for
+/// `X` to occur in a non-covariant position in a member signature in the body
+/// of `D`, except that it is not an error if it occurs in a covariant position
+/// in the type annotation of a formal parameter which is covariant (this is a
+/// contravariant position in the member signature as a whole).
+///
+/// In particular, `X` can not be the type of a method parameter (unless it is
+/// covariant). It can never be the bound of a type parameter of a generic
+/// method
+///
+/// @description Check that it is a compile-time error if a type parameter has a
+/// variance modifier `out` and occurs in a contravariant position in a member
+/// signature in the body of `D`
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=variance,inline-class
+
+class C<out X> {
+  C(X x) {} // No error here
+  factory C.f(X x) => C(x); // And here
+
+  void f(X x) {}
+//       ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(X x) {}
+//           ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+mixin M<out X> {
+  void f(X x);
+//       ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(X x);
+//           ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+enum E<out X> {
+  e;
+
+  const E();
+  const E.n(X x); // No error here
+
+  void f(X x) {}
+//       ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(X x) {}
+//           ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension type ET<out X>(X x) {
+  ET.n(X x) : this.x = x; // No error here
+
+  void f(X x) {}
+//       ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(X x) {}
+//           ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+void main() {
+  print(C);
+  print(M);
+  print(E);
+  print(ET);
+}
diff --git a/TypeSystem/type-variance/out_non_covariant_A01_t02.dart b/TypeSystem/type-variance/out_non_covariant_A01_t02.dart
new file mode 100644
index 0000000..254b8c6
--- /dev/null
+++ b/TypeSystem/type-variance/out_non_covariant_A01_t02.dart
@@ -0,0 +1,68 @@
+// Copyright (c) 2024, 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.
+
+/// @assertion Let `D` be the declaration of a class or mixin, enum or a type
+/// extension and let `X` be a type parameter declared by `D`.
+///
+/// If `X` has the variance modifier `out` then it is a compile-time error for
+/// `X` to occur in a non-covariant position in a member signature in the body
+/// of `D`, except that it is not an error if it occurs in a covariant position
+/// in the type annotation of a formal parameter which is covariant (this is a
+/// contravariant position in the member signature as a whole).
+///
+/// In particular, `X` can not be the type of a method parameter (unless it is
+/// covariant). It can never be the bound of a type parameter of a generic
+/// method
+///
+/// @description Check that it is a compile-time error if a type parameter has a
+/// variance modifier `out` and occurs in a contravariant position in a member
+/// signature in the body of `D`
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=variance,inline-class
+
+class C<out X> {
+  C([X? x]) {} // No error here
+  factory C.f([X? x]) => C(x); // And here
+
+  void f([X? x]) {}
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+mixin M<out X> {
+  void f([X? x]);
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+enum E<out X> {
+  e;
+
+  const E();
+  const E.n([X? x]); // No error here
+
+  void f([X? x]) {}
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension type ET<out X>(X? x) {
+  ET.n([X? x]) : this.x = x; // No error here
+
+  void f([X? x]) {}
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+void main() {
+  print(C);
+  print(M);
+  print(E);
+  print(ET);
+}
diff --git a/TypeSystem/type-variance/out_non_covariant_A01_t03.dart b/TypeSystem/type-variance/out_non_covariant_A01_t03.dart
new file mode 100644
index 0000000..cad7099
--- /dev/null
+++ b/TypeSystem/type-variance/out_non_covariant_A01_t03.dart
@@ -0,0 +1,68 @@
+// Copyright (c) 2024, 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.
+
+/// @assertion Let `D` be the declaration of a class or mixin, enum or a type
+/// extension and let `X` be a type parameter declared by `D`.
+///
+/// If `X` has the variance modifier `out` then it is a compile-time error for
+/// `X` to occur in a non-covariant position in a member signature in the body
+/// of `D`, except that it is not an error if it occurs in a covariant position
+/// in the type annotation of a formal parameter which is covariant (this is a
+/// contravariant position in the member signature as a whole).
+///
+/// In particular, `X` can not be the type of a method parameter (unless it is
+/// covariant). It can never be the bound of a type parameter of a generic
+/// method
+///
+/// @description Check that it is a compile-time error if a type parameter has a
+/// variance modifier `out` and occurs in a contravariant position in a member
+/// signature in the body of `D`
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=variance,inline-class
+
+class C<out X> {
+  C({X? x}) {} // No error here
+  factory C.f({X? x}) => C(x); // And here
+
+  void f({X? x}) {}
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+mixin M<out X> {
+  void f({X? x});
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+enum E<out X> {
+  e;
+
+  const E();
+  const E.n({X? x}); // No error here
+
+  void f({X? x}) {}
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension type ET<out X>(X? x) {
+  ET.n({X? x}) : this.x = x; // No error here
+
+  void f({X? x}) {}
+//        ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+void main() {
+  print(C);
+  print(M);
+  print(E);
+  print(ET);
+}
diff --git a/TypeSystem/type-variance/out_non_covariant_A01_t04.dart b/TypeSystem/type-variance/out_non_covariant_A01_t04.dart
new file mode 100644
index 0000000..d67dd53
--- /dev/null
+++ b/TypeSystem/type-variance/out_non_covariant_A01_t04.dart
@@ -0,0 +1,89 @@
+// Copyright (c) 2024, 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.
+
+/// @assertion Let `D` be the declaration of a class or mixin, enum or a type
+/// extension and let `X` be a type parameter declared by `D`.
+///
+/// If `X` has the variance modifier `out` then it is a compile-time error for
+/// `X` to occur in a non-covariant position in a member signature in the body
+/// of `D`, except that it is not an error if it occurs in a covariant position
+/// in the type annotation of a formal parameter which is covariant (this is a
+/// contravariant position in the member signature as a whole).
+///
+/// In particular, `X` can not be the type of a method parameter (unless it is
+/// covariant). It can never be the bound of a type parameter of a generic
+/// method
+///
+/// @description Check that it is a compile-time error if a type parameter has a
+/// variance modifier `out` and occurs in a contravariant position in a member
+/// signature in the body of `D` (it occurs in a contravariant position in a
+/// covariant parameter).
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=variance,inline-class
+
+typedef C<T> = T;
+typedef ContravariantT<T> = void Function(T);
+
+class A<out X> {
+  final C<ContravariantT<X>>? v = null;
+//                           ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  C<ContravariantT<X>>? f() {}
+//^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  C<ContravariantT<X>>? get g => null;
+//^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+mixin M<out X> {
+  C<ContravariantT<X>>? f() {}
+//^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  C<ContravariantT<X>>? get g => null;
+//^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+enum E<out X> {
+  e;
+
+  ContravariantT<X>? f() {}
+//^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  ContravariantT<X>? get g => null;
+//^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension type ET<out X>(X x) {
+  ContravariantT<X>? f() {}
+//^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  ContravariantT<X>? get g => null;
+//^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+void main() {
+  print(C);
+  print(M);
+  print(E);
+  print(ET);
+}
diff --git a/TypeSystem/type-variance/out_non_covariant_A01_t05.dart b/TypeSystem/type-variance/out_non_covariant_A01_t05.dart
new file mode 100644
index 0000000..f2c8764
--- /dev/null
+++ b/TypeSystem/type-variance/out_non_covariant_A01_t05.dart
@@ -0,0 +1,85 @@
+// Copyright (c) 2024, 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.
+
+/// @assertion Let `D` be the declaration of a class or mixin, enum or a type
+/// extension and let `X` be a type parameter declared by `D`.
+///
+/// If `X` has the variance modifier `out` then it is a compile-time error for
+/// `X` to occur in a non-covariant position in a member signature in the body
+/// of `D`, except that it is not an error if it occurs in a covariant position
+/// in the type annotation of a formal parameter which is covariant (this is a
+/// contravariant position in the member signature as a whole).
+///
+/// In particular, `X` can not be the type of a method parameter (unless it is
+/// covariant). It can never be the bound of a type parameter of a generic
+/// method
+///
+/// @description Check that it is a compile-time error if a type parameter has a
+/// variance modifier `out` and occurs in a contravariant position in a member
+/// signature in the body of `D` (it occurs in a covariant position in a
+/// contravariant parameter).
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=variance,inline-class
+
+typedef CovariantT<T> = T Function();
+
+class C<out X> {
+  final CovariantT<X>? v = null; // Ok, covariant
+
+  f(CovariantT<X> v) {}
+//  ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(CovariantT<X> v) {}
+//           ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+mixin M<out X> {
+  f(CovariantT<X> v) {}
+//  ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(CovariantT<X> v) {}
+//           ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+enum E<out X> {
+  e;
+
+  f(CovariantT<X> v) {}
+//  ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(CovariantT<X> v) {}
+//           ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension type ET<out X>(X x) {
+  f(CovariantT<X> v) {}
+//  ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  void set s(CovariantT<X> v) {}
+//           ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+void main() {
+  print(C);
+  print(M);
+  print(E);
+  print(ET);
+}
diff --git a/TypeSystem/type-variance/out_non_covariant_A01_t06.dart b/TypeSystem/type-variance/out_non_covariant_A01_t06.dart
new file mode 100644
index 0000000..8768a65
--- /dev/null
+++ b/TypeSystem/type-variance/out_non_covariant_A01_t06.dart
@@ -0,0 +1,90 @@
+// Copyright (c) 2024, 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.
+
+/// @assertion Let `D` be the declaration of a class or mixin, enum or a type
+/// extension and let `X` be a type parameter declared by `D`.
+///
+/// If `X` has the variance modifier `out` then it is a compile-time error for
+/// `X` to occur in a non-covariant position in a member signature in the body
+/// of `D`, except that it is not an error if it occurs in a covariant position
+/// in the type annotation of a formal parameter which is covariant (this is a
+/// contravariant position in the member signature as a whole).
+///
+/// In particular, `X` can not be the type of a method parameter (unless it is
+/// covariant). It can never be the bound of a type parameter of a generic
+/// method
+///
+/// @description Check that it is a compile-time error if a type parameter has a
+/// variance modifier `out` and occurs in a contravariant position in a member
+/// signature in the body of `D` (it occurs in a contravariant position in a
+/// `FutureOr<U>` type).
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=variance,inline-class
+
+import 'dart:async';
+
+typedef ContravariantT<T> = void Function(T);
+
+class C<out X> {
+  final FutureOr<ContravariantT<X>>? v = null;
+//                                  ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  FutureOr<ContravariantT<X>>? f() {}
+//^^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  FutureOr<ContravariantT<X>>? get g => null;
+//^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+mixin M<out X> {
+  FutureOr<ContravariantT<X>>? f() {}
+//^^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  FutureOr<ContravariantT<X>>? get g => null;
+//^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+enum E<out X> {
+  e;
+
+  FutureOr<ContravariantT<X>>? f() {}
+//^^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  FutureOr<ContravariantT<X>>? get g => null;
+//^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension type ET<out X>(X x) {
+  FutureOr<ContravariantT<X>>? f() {}
+//^^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+  FutureOr<ContravariantT<X>>? get g => null;
+//^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+void main() {
+  print(C);
+  print(M);
+  print(E);
+  print(ET);
+}