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>
This commit is contained in:
Leaf Petersen 2023-03-10 06:02:34 +00:00 committed by Commit Queue
parent 737b6f7356
commit 34531dcdf2
3 changed files with 115 additions and 0 deletions

View file

@ -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() {}

View file

@ -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() {}

View file

@ -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();
}