Update tests of sealed mixin on type to reflect spec change.

As of https://github.com/dart-lang/language/pull/2889 it is an error
to declare a mixin with an `on` type which is declared in a different
library.

Change-Id: I02d6b3b6c203a46c74d2eacd006181db8e563726
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290022
Reviewed-by: Kallen Tu <kallentu@google.com>
This commit is contained in:
Leaf Petersen 2023-03-22 03:16:38 +00:00
parent 38565dfe8b
commit ba9535fee8
3 changed files with 40 additions and 46 deletions

View file

@ -0,0 +1,35 @@
// 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=sealed-class
import 'sealed_class_mixin_on_lib.dart';
// It is an error to declare a mixin with an `on` type which is a sealed class
// from another library.
mixin MA on SealedClass {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
// It is not an error to declare a mixin with an `on` type which is a subtype of
// a sealed class from another library if the subclass is not otherwise
// restricted.
mixin MB on A {}
// It is an error to apply a mixin with an `on` type which is sealed to the
// sealed class which is its `on` type outside of the library which declares the
// `on` type.
class ConcreteA extends SealedClass with M {}
// ^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_USE_OF_TYPE_OUTSIDE_LIBRARY
// [cfe] The class 'SealedClass' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
// It is not an error to apply a mixin with an `on` type which is sealed to a
// subtype of the sealed class.
class ConcreteB extends A with M {}
// It is not an error to apply a mixin with an `on` type which is a subtype of a
// sealed class from another library to a subtype of the sealed class.
class ConcreteC extends A with MB {}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// 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.
@ -12,8 +12,8 @@ abstract class A extends SealedClass {}
class B extends SealedClass {}
sealed mixin SealedMixin {}
// It is legal to declare a mixin whose `on` type is a sealed type from the
// same library.
mixin M on SealedClass {}
class C extends SealedClass with SealedMixin {}
class D with SealedMixin {}
class C extends SealedClass with M {}

View file

@ -1,41 +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
// Allow a sealed type to appear in the "on" clause of a mixin declaration in
// another library.
import "package:expect/expect.dart";
import 'sealed_class_mixin_on_lib.dart';
mixin MA on SealedClass {}
mixin MB on SealedClass {}
class ConcreteA extends A with MA, MB {
int foo = 0;
}
mixin MC on SealedClass, SealedMixin {}
class ConcreteC extends C with MC {
int foo = 0;
}
mixin MCSingular on SealedMixin {}
class ConcreteD extends D with MCSingular {
int foo = 0;
}
main() {
var concreteA = ConcreteA();
Expect.equals(0, concreteA.foo);
var concreteC = ConcreteC();
Expect.equals(0, concreteC.foo);
var concreteD = ConcreteD();
Expect.equals(0, concreteD.foo);
}