Tests for mixin class legacy interactions.

Change-Id: I2d2c3353f77b96d656bc81dc5f59bd7021ed2861
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287665
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
diff --git a/tests/language/class_modifiers/mixin/mixin_class_legacy_interactions_forward_error_test.dart b/tests/language/class_modifiers/mixin/mixin_class_legacy_interactions_forward_error_test.dart
new file mode 100644
index 0000000..da4b297
--- /dev/null
+++ b/tests/language/class_modifiers/mixin/mixin_class_legacy_interactions_forward_error_test.dart
@@ -0,0 +1,49 @@
+// Copyright (c) 2023, 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.
+
+// @dart=2.19
+
+// SharedOptions=--enable-experiment=class-modifiers
+
+// Test the behavior of mixing in classes defined in a 3.0 library (both SDK
+// and non SDK) when the mixin happens in a pre 3.0 library.
+
+import 'dart:collection';
+import 'mixin_class_lib.dart';
+
+/// Test mixing in things from the SDK core libraries.
+
+/// Test that it is not an error to mix in a class (which is not marked as a
+/// mixin class) from the core libraries if it was valid to do so pre 3.0.
+class A with Comparable<int> {
+  int compareTo(int x) => 0;
+}
+
+/// Test that it is not an error to mix in a mixin from the core libraries even
+/// if it has a generative constructor.
+abstract class B with Iterable<int> {}
+
+/// Test that it continues to be an error to mix in a class (which is not marked
+/// as a mixin class) from the core libraries if it was not valid to do so pre
+/// 3.0.
+class C with Error {}
+//    ^
+// [cfe] Can't use 'Error' as a mixin because it has constructors.
+//           ^^^^^
+// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR
+
+/// Test mixing in things from the non-SDK libraries.
+
+/// Test that it is an error to mix in a class (which is not marked as a mixin
+/// class) from a 3.0 non core library.
+class D with NotAMixinClass {}
+//           ^^^^^^^^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CLASS_USED_AS_MIXIN
+// [cfe] unspecified
+
+/// Test that it is not an error to mix in a mixin class from a 3.0 non core
+/// library.
+class E with Class {}
+
+void main() {}
diff --git a/tests/language/class_modifiers/mixin/mixin_class_legacy_interactions_reverse_error_test.dart b/tests/language/class_modifiers/mixin/mixin_class_legacy_interactions_reverse_error_test.dart
new file mode 100644
index 0000000..670e425
--- /dev/null
+++ b/tests/language/class_modifiers/mixin/mixin_class_legacy_interactions_reverse_error_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2023, 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=class-modifiers
+
+// Test the behavior of mixing in classes defined in a pre 3.0 library
+// when the mixin happens in a 3.0 library.
+
+import 'mixin_class_legacy_lib.dart' as legacy;
+
+/// Test mixing in things from the core libraries.
+
+/// Test that it is an error to mix in a class (which is not marked as a
+/// mixin class) from the core libraries in 3.0.
+class A with Comparable<int> {
+//           ^^^^^^^^^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CLASS_USED_AS_MIXIN
+// [cfe] The class 'Comparable' can't be used as a mixin because it isn't a mixin class nor a mixin.
+  int compareTo(int x) => 0;
+}
+
+/// Test mixing in things from a 3.0 library exported through a pre 3.0 library.
+
+/// Test that it is an error to mix in a class (which is not marked as a mixin
+/// class) from a 3.0 non core library exported through a pre 3.0 library
+class B with legacy.NotAMixinClass {}
+//           ^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.CLASS_USED_AS_MIXIN
+// [cfe] The class 'NotAMixinClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
+
+/// Test that it is not an error to mix in a mixin class from a 3.0 non core
+/// library exported through a pre 3.0 library.
+class C with legacy.Class {}
+
+/// Test mixing in things from a pre 3.0 library.
+
+/// Test that it is not an error to mix in a class from a 3.0 non core library,
+/// when it would have been valid to do so in a pre 3.0 library.
+class D with legacy.LegacyNotAMixinClass {}
+
+/// Test that it is an error to mix in a class from a 3.0 non core library,
+/// when it would not have been valid to do so in a pre 3.0 library.
+class E with legacy.LegacyNotAMixinClassWithConstructor {}
+//    ^
+// [cfe] Can't use 'LegacyNotAMixinClassWithConstructor' as a mixin because it has constructors.
+//           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_CONSTRUCTOR
+
+main() {}
diff --git a/tests/language/class_modifiers/mixin/mixin_class_legacy_lib.dart b/tests/language/class_modifiers/mixin/mixin_class_legacy_lib.dart
new file mode 100644
index 0000000..09560ee5
--- /dev/null
+++ b/tests/language/class_modifiers/mixin/mixin_class_legacy_lib.dart
@@ -0,0 +1,16 @@
+// Copyright (c) 2023, 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.
+
+// @dart=2.19
+
+// Provide classes from a pre 3.0 library for use in tests of behaviors around
+// mixin classes crossing language versions.
+
+export 'mixin_class_lib.dart' show NotAMixinClass, Class;
+
+class LegacyNotAMixinClass {}
+
+class LegacyNotAMixinClassWithConstructor {
+  LegacyNotAMixinClassWithConstructor();
+}