Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2371. Add tests for factory constructor generating an enum value #2376

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions LanguageFeatures/Enhanced-Enum/factory_constructor_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 It is a compile-time error if the constructor implicitly invoked
/// by an enumerated enum value declaration is a factory constructor.
///
/// @description Check that It is a compile-time error if the constructor
/// implicitly invoked by an enumerated enum value declaration is a factory
/// constructor
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class

enum E1 {
e1,
e2.foo();
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
const E1();
const factory E1.foo() = ET1.foo;
}

extension type const ET1(E1 it) implements E1 {
const ET1.foo() : this(E1.e1);
}

void main() {
print(identical(E1.e1, E1.e2));
}
31 changes: 31 additions & 0 deletions LanguageFeatures/Enhanced-Enum/factory_constructor_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 It is a compile-time error if the constructor implicitly invoked
/// by an enumerated enum value declaration is a factory constructor.
///
/// @description Check that It is a compile-time error if the constructor
/// implicitly invoked by an enumerated enum value declaration is a factory
/// constructor
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=inline-class

enum E {
e1.foo();
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

const E();
const factory E.foo() = ET.foo;
}

extension type const ET(E it) implements E {
const ET.foo() : this(E.e1);
}

void main() {
print(E.e1);
}