[tests] Fix tests to report an error when classes are used as a mixin, even in the same library.

Change-Id: Icdb4c4e87bf3143ea9c37272f27e7eac0c7613a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283129
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
Kallen Tu 2023-02-15 15:26:49 +00:00 committed by Commit Queue
parent 3a1ac23ea2
commit 50e1400d97
6 changed files with 47 additions and 103 deletions

View file

@ -0,0 +1,45 @@
// 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
// Error when mixing in a regular class inside its library.
class Class {
int foo = 0;
}
mixin Mixin {
int foo = 0;
}
abstract class A with Class {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
class B with Class {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
class C = Object with Class;
// ^
// [analyzer] unspecified
// [cfe] unspecified
abstract class D with Class, Mixin {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
class E with Class, Mixin {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
class NamedMixinClassApplication = Object with Class;
// ^
// [analyzer] unspecified
// [cfe] unspecified

View file

@ -1,47 +0,0 @@
// 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
// Mixing in a regular class inside its library.
import 'package:expect/expect.dart';
class Class {
int foo = 0;
}
mixin Mixin {
int foo = 0;
}
abstract class A with Class {}
class AImpl extends A {}
class B with Class {}
class C = Object with Class;
abstract class D with Class, Mixin {}
class DImpl extends D {}
class E with Class, Mixin {}
class NamedMixinClassApplication = Object with Mixin;
class F with NamedMixinClassApplication {
// To avoid runtime error with DDC until issue 50489 is fixed.
int foo = 0;
}
main() {
Expect.equals(0, AImpl().foo);
Expect.equals(0, B().foo);
Expect.equals(0, C().foo);
Expect.equals(0, DImpl().foo);
Expect.equals(0, E().foo);
Expect.equals(0, F().foo);
}

View file

@ -11,7 +11,3 @@ part of 'mixin_class_part_test.dart';
class A with MixinClass {}
abstract class B with MixinClass {}
class NonMixinClass {
int foo = 0;
}

View file

@ -16,10 +16,7 @@ mixin class MixinClass {
class BImpl extends B {}
class WithNonMixinClass with NonMixinClass {}
main() {
Expect.equals(0, A().foo);
Expect.equals(0, BImpl().foo);
Expect.equals(0, WithNonMixinClass().foo);
}

View file

@ -7,9 +7,9 @@
// Error when applying the mixin modifier to a class whose superclass is not
// Object.
class NotObject {}
mixin class NotObject {}
class AlsoNotObject {}
mixin class AlsoNotObject {}
mixin class MixinClass extends NotObject {}
// ^^^^^^^^^

View file

@ -1,47 +0,0 @@
// Copyright (c) 2022, 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=sealed-class,class-modifiers
// Allow mixing in a sealed class inside of library.
import "package:expect/expect.dart";
sealed class SealedClass {
int foo = 0;
}
sealed mixin SealedMixin {}
class Class {
int foo = 0;
}
mixin Mixin {}
abstract class A with SealedClass {}
class AImpl extends A {}
class B with SealedClass {}
abstract class C = Object with SealedClass;
class CImpl extends C {}
abstract class D with SealedClass, Class {}
class DImpl extends D {}
class E with Class, SealedMixin {}
abstract class F with Mixin, SealedClass {}
class FImpl extends F {}
main() {
Expect.equals(0, AImpl().foo);
Expect.equals(0, B().foo);
Expect.equals(0, CImpl().foo);
Expect.equals(0, DImpl().foo);
Expect.equals(0, E().foo);
Expect.equals(0, FImpl().foo);
}