forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#1959. Test for restrictions of valid combinations of modifiers
- Loading branch information
Showing
11 changed files
with
733 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
LanguageFeatures/Class-modifiers/syntax_base_class_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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 {} | ||
|
||
base class BaseClassExtendsLocalBaseClass extends LocalBaseClass {} | ||
|
||
final class FinalClassExtendsLocalBaseClass extends LocalBaseClass {} | ||
|
||
sealed class SealedClassExtendsLocalBaseClass extends LocalBaseClass {} | ||
|
||
main() { | ||
BaseClass(); | ||
LocalBaseClass(); | ||
|
||
print(BaseClassExtendsBaseClass); | ||
print(FinalClassExtendsBaseClass); | ||
print(SealedClassExtendsBaseClass); | ||
print(BaseClassExtendsLocalBaseClass); | ||
print(FinalClassExtendsLocalBaseClass); | ||
print(SealedClassExtendsLocalBaseClass); | ||
} |
33 changes: 33 additions & 0 deletions
33
LanguageFeatures/Class-modifiers/syntax_base_class_A02_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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 | ||
|
||
main() { | ||
print(BaseClassImplementsBaseClass); | ||
print(FinalClassImplementsBaseClass); | ||
print(SealedClassImplementsBaseClass); | ||
} |
26 changes: 26 additions & 0 deletions
26
LanguageFeatures/Class-modifiers/syntax_base_class_A02_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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 {} | ||
|
||
main() { | ||
print(BaseClassImplementsLocalBaseClass); | ||
print(FinalClassImplementsLocalBaseClass); | ||
print(SealedClassImplementsLocalBaseClass); | ||
} |
91 changes: 91 additions & 0 deletions
91
LanguageFeatures/Class-modifiers/syntax_base_class_A03_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// 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 | ||
|
||
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 | ||
|
||
main() { | ||
print(BaseClassWithBaseClass1); | ||
print(BaseClassWithBaseClass2); | ||
print(FinalClassWithBaseClass1); | ||
print(FinalClassWithBaseClass2); | ||
print(SealedClassWithBaseClass1); | ||
print(SealedClassWithBaseClass2); | ||
print(BaseClassWithLocalBaseClass1); | ||
print(BaseClassWithLocalBaseClass2); | ||
print(FinalClassWithLocalBaseClass1); | ||
print(FinalClassWithLocalBaseClass2); | ||
print(SealedClassWithLocalBaseClass1); | ||
print(SealedClassWithLocalBaseClass2); | ||
} |
44 changes: 44 additions & 0 deletions
44
LanguageFeatures/Class-modifiers/syntax_base_class_A04_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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 {} | ||
sealed class SealedExtendsC1 extends C {} | ||
sealed class SealedExtendsC2 extends C {} | ||
|
||
String test1(C c) => switch (c) { | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
ExtendsC1 _ => "ExtendsC1", | ||
ExtendsC2 _ => "ExtendsC2", | ||
SealedExtendsC1 _ => "SealedExtendsC1", | ||
SealedExtendsC2 _ => "SealedExtendsC2" | ||
}; | ||
|
||
String test2(BaseClass c) => switch (c) { | ||
// ^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
BaseExtendsBaseClass1 _ => "BaseExtendsBaseClass1", | ||
BaseExtendsBaseClass2 _ => "BaseExtendsBaseClass2", | ||
SealedExtendsBaseClass1 _ => "SealedExtendsBaseClass1", | ||
SealedExtendsBaseClass2 _ => "SealedExtendsBaseClass2" | ||
}; | ||
|
||
main() { | ||
test1(ExtendsC1()); | ||
test2(BaseExtendsBaseClass1()); | ||
} |
92 changes: 92 additions & 0 deletions
92
LanguageFeatures/Class-modifiers/syntax_class_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// 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 Class with no modifiers can be constructed, extended, implemented | ||
/// but not mixed in and is not exhaustive | ||
/// | ||
/// @description Checks that class with no modifiers can be constructed, | ||
/// extended and implemented in the same library | ||
/// @author [email protected] | ||
// SharedOptions=--enable-experiment=class-modifiers | ||
|
||
class Class {} | ||
|
||
class ClassExtendsClass extends Class {} | ||
|
||
base class BaseClassExtendsClass extends Class {} | ||
|
||
interface class InterfaceClassExtendsClass extends Class {} | ||
|
||
final class FinalClassExtendsClass extends Class {} | ||
|
||
sealed class SealedClassExtendsClass extends Class {} | ||
|
||
abstract class AbstractClassExtendsClass extends Class {} | ||
|
||
abstract base class AbstractBaseClassExtendsClass extends Class {} | ||
|
||
abstract interface class AbstractInterfaceClassExtendsClass extends Class {} | ||
|
||
abstract final class AbstractFinalClassExtendsClass extends Class {} | ||
|
||
class ClassImplementsClass implements Class {} | ||
|
||
base class BaseClassImplementsClass implements Class {} | ||
|
||
interface class InterfaceClassImplementsClass implements Class {} | ||
|
||
final class FinalClassImplementsClass implements Class {} | ||
|
||
sealed class SealedClassImplementsClass implements Class {} | ||
|
||
abstract class AbstractClassImplementsClass implements Class {} | ||
|
||
abstract base class AbstractBaseClassImplementsClass implements Class {} | ||
|
||
abstract interface class AbstractInterfaceClassImplementsClass | ||
implements Class {} | ||
|
||
abstract final class AbstractFinalClassImplementsClass implements Class {} | ||
|
||
mixin class MixinClassImplementsClass implements Class {} | ||
|
||
base mixin class BaseMixinClassImplementsClass implements Class {} | ||
|
||
abstract mixin class AbstractMixinClassImplementsClass implements Class {} | ||
|
||
abstract base mixin class AbstractBaseMixinClassImplementsClass | ||
implements Class {} | ||
|
||
mixin MixinImplementsClass implements Class {} | ||
|
||
base mixin BaseMixinImplementsClass implements Class {} | ||
|
||
main() { | ||
Class(); | ||
print(ClassExtendsClass); | ||
print(BaseClassExtendsClass); | ||
print(InterfaceClassExtendsClass); | ||
print(FinalClassExtendsClass); | ||
print(SealedClassExtendsClass); | ||
print(AbstractClassExtendsClass); | ||
print(AbstractBaseClassExtendsClass); | ||
print(AbstractInterfaceClassExtendsClass); | ||
print(AbstractFinalClassExtendsClass); | ||
print(ClassImplementsClass); | ||
print(BaseClassImplementsClass); | ||
print(InterfaceClassImplementsClass); | ||
print(FinalClassImplementsClass); | ||
print(SealedClassImplementsClass); | ||
print(AbstractClassImplementsClass); | ||
print(AbstractBaseClassImplementsClass); | ||
print(AbstractInterfaceClassImplementsClass); | ||
print(AbstractFinalClassImplementsClass); | ||
print(MixinClassImplementsClass); | ||
print(BaseMixinClassImplementsClass); | ||
print(AbstractMixinClassImplementsClass); | ||
print(AbstractBaseMixinClassImplementsClass); | ||
print(MixinImplementsClass); | ||
print(BaseMixinImplementsClass); | ||
} |
Oops, something went wrong.