Skip to content

Commit

Permalink
#1959. Test valid combinations of modifiers. Part 1 (#2023)
Browse files Browse the repository at this point in the history
Test for restrictions of valid combinations of modifiers.
  • Loading branch information
sgrekhov authored Apr 19, 2023
1 parent f052bbe commit 4b81577
Show file tree
Hide file tree
Showing 32 changed files with 2,278 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LanguageFeatures/Class-modifiers/class_modifiers_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ typedef TypedefAbstractBaseMixinClass = AbstractBaseMixinClass;
typedef TypedefMixin = Mixin;
typedef TypedefBaseMixin = BaseMixin;

class ExtendsClass1 extends Class {}
class ExtendsClass2 extends Class {}

base class BaseExtendsBaseClass1 extends BaseClass {}
base class BaseExtendsBaseClass2 extends BaseClass {}

class ExtendsInterfaceClass1 extends InterfaceClass {} // reopen
interface class ExtendsInterfaceClass2 extends InterfaceClass {}

final class ExtendsFinalClass1 extends FinalClass {}
final class ExtendsFinalClass2 extends FinalClass {}

class ExtendsSealedClass extends SealedClass {}
class ImplementsSealedClass implements SealedClass {}
mixin MixinOnSealed on SealedClass {}

ExtendsSealedClass extendsSealedClass = ExtendsSealedClass();
55 changes: 55 additions & 0 deletions LanguageFeatures/Class-modifiers/syntax_base_class_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.

/// @assertion Base class can be constructed and extended but not implemented,
/// mixed in and is not exhaustive
///
/// @description Checks that `base class` can be constructed and extended by
/// `base/final/sealed` classes
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

import "class_modifiers_lib.dart";

base class LocalBaseClass {}

base class BaseClassExtendsBaseClass extends BaseClass {}

final class FinalClassExtendsBaseClass extends BaseClass {}

sealed class SealedClassExtendsBaseClass extends BaseClass {}

abstract base class AbstractBaseClassExtendsBaseClass extends BaseClass {}

abstract final class AbstractFinalClassExtendsBaseClass extends BaseClass {}

base class BaseClassExtendsLocalBaseClass extends LocalBaseClass {}

final class FinalClassExtendsLocalBaseClass extends LocalBaseClass {}

sealed class SealedClassExtendsLocalBaseClass extends LocalBaseClass {}

abstract base class AbstractBaseClassExtendsLocalBaseClass
extends LocalBaseClass {}

abstract final class AbstractFinalClassExtendsLocalBaseClass
extends LocalBaseClass {}

main() {
BaseClass();
LocalBaseClass();

print(BaseClassExtendsBaseClass);
print(FinalClassExtendsBaseClass);
print(SealedClassExtendsBaseClass);
print(AbstractBaseClassExtendsBaseClass);
print(AbstractFinalClassExtendsBaseClass);

print(BaseClassExtendsLocalBaseClass);
print(FinalClassExtendsLocalBaseClass);
print(SealedClassExtendsLocalBaseClass);
print(AbstractBaseClassExtendsLocalBaseClass);
print(AbstractFinalClassExtendsLocalBaseClass);
}
47 changes: 47 additions & 0 deletions LanguageFeatures/Class-modifiers/syntax_base_class_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.

/// @assertion Base class can be constructed and extended but not implemented,
/// mixed in and is not exhaustive
///
/// @description Checks that it is a compile-time error if a `base class` is
/// implemented outside of the library where it is defined
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

import "class_modifiers_lib.dart";

base class BaseClassImplementsBaseClass implements BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

final class FinalClassImplementsBaseClass implements BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

sealed class SealedClassImplementsBaseClass implements BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract base class AbstractBaseClassImplementsBaseClass implements BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract final class AbstractFinalClassImplementsBaseClass implements BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(BaseClassImplementsBaseClass);
print(FinalClassImplementsBaseClass);
print(SealedClassImplementsBaseClass);
print(AbstractBaseClassImplementsBaseClass);
print(AbstractFinalClassImplementsBaseClass);
}
34 changes: 34 additions & 0 deletions LanguageFeatures/Class-modifiers/syntax_base_class_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.

/// @assertion Base class can be constructed and extended but not implemented,
/// mixed in and is not exhaustive
///
/// @description Checks that it is not an error if a `base class` is
/// implemented in the same library where it is defined
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

base class LocalBaseClass {}

base class BaseClassImplementsLocalBaseClass implements LocalBaseClass {}

final class FinalClassImplementsLocalBaseClass implements LocalBaseClass {}

sealed class SealedClassImplementsLocalBaseClass implements LocalBaseClass {}

abstract base class AbstractBaseClassImplementsLocalBaseClass
implements LocalBaseClass {}

abstract final class AbstractFinalClassImplementsLocalBaseClass
implements LocalBaseClass {}

main() {
print(BaseClassImplementsLocalBaseClass);
print(FinalClassImplementsLocalBaseClass);
print(SealedClassImplementsLocalBaseClass);
print(AbstractBaseClassImplementsLocalBaseClass);
print(AbstractFinalClassImplementsLocalBaseClass);
}
140 changes: 140 additions & 0 deletions LanguageFeatures/Class-modifiers/syntax_base_class_A03_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// 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.

/// @assertion Base class can be constructed and extended but not implemented,
/// mixed in and is not exhaustive
///
/// @description Checks that it is a compile-time error if a `base class` is
/// mixed in
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

import "class_modifiers_lib.dart";

base class LocalBaseClass {}

base class BaseClassWithBaseClass1 with BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

base class BaseClassWithBaseClass2 = Object with BaseClass;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

final class FinalClassWithBaseClass1 with BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

final class FinalClassWithBaseClass2 = Object with BaseClass;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

sealed class SealedClassWithBaseClass1 with BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

sealed class SealedClassWithBaseClass2 = Object with BaseClass;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract base class AbstractBaseClassWithBaseClass1 with BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract base class AbstractBaseClassWithBaseClass2 = Object with BaseClass;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract final class AbstractFinalClassWithBaseClass1 with BaseClass {}
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract final class AbstractFinalClassWithBaseClass2 = Object with BaseClass;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

base class BaseClassWithLocalBaseClass1 with LocalBaseClass {}
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

base class BaseClassWithLocalBaseClass2 = Object with LocalBaseClass;
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

final class FinalClassWithLocalBaseClass1 with LocalBaseClass {}
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

final class FinalClassWithLocalBaseClass2 = Object with LocalBaseClass;
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

sealed class SealedClassWithLocalBaseClass1 with LocalBaseClass {}
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

sealed class SealedClassWithLocalBaseClass2 = Object with LocalBaseClass;
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract base class AbstractBaseClassWithLocalBaseClass1 with LocalBaseClass {}
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract base class AbstractBaseClassWithLocalBaseClass2 = Object with LocalBaseClass;
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract final class AbstractFinalClassWithLocalBaseClass1 with LocalBaseClass {}
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

abstract final class AbstractFinalClassWithLocalBaseClass2 = Object with LocalBaseClass;
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(BaseClassWithBaseClass1);
print(BaseClassWithBaseClass2);
print(FinalClassWithBaseClass1);
print(FinalClassWithBaseClass2);
print(SealedClassWithBaseClass1);
print(SealedClassWithBaseClass2);
print(AbstractBaseClassWithBaseClass1);
print(AbstractBaseClassWithBaseClass2);
print(AbstractFinalClassWithBaseClass1);
print(AbstractFinalClassWithBaseClass2);

print(BaseClassWithLocalBaseClass1);
print(BaseClassWithLocalBaseClass2);
print(FinalClassWithLocalBaseClass1);
print(FinalClassWithLocalBaseClass2);
print(SealedClassWithLocalBaseClass1);
print(SealedClassWithLocalBaseClass2);
print(AbstractBaseClassWithLocalBaseClass1);
print(AbstractBaseClassWithLocalBaseClass2);
print(AbstractFinalClassWithLocalBaseClass1);
print(AbstractFinalClassWithLocalBaseClass2);
}
38 changes: 38 additions & 0 deletions LanguageFeatures/Class-modifiers/syntax_base_class_A04_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

/// @assertion Base class can be constructed and extended but not implemented,
/// mixed in and is not exhaustive
///
/// @description Checks that `base class` is not exhaustive
/// @author [email protected]
// SharedOptions=--enable-experiment=class-modifiers

import "class_modifiers_lib.dart";

base class C {}
base class ExtendsC1 extends C {}
base class ExtendsC2 extends C {}

String test1(C c) => switch (c) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
ExtendsC1 _ => "ExtendsC1",
ExtendsC2 _ => "ExtendsC2",
};

String test2(BaseClass c) => switch (c) {
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
BaseExtendsBaseClass1 _ => "BaseExtendsBaseClass1",
BaseExtendsBaseClass2 _ => "BaseExtendsBaseClass2",
};

main() {
test1(ExtendsC1());
test2(BaseExtendsBaseClass1());
}
Loading

0 comments on commit 4b81577

Please sign in to comment.