diff --git a/LanguageFeatures/Enhanced-Enum/grammar_A09_t04.dart b/LanguageFeatures/Enhanced-Enum/grammar_A09_t04.dart index 71d0c7e614..2483f22340 100644 --- a/LanguageFeatures/Enhanced-Enum/grammar_A09_t04.dart +++ b/LanguageFeatures/Enhanced-Enum/grammar_A09_t04.dart @@ -24,7 +24,7 @@ enum E1 { e2(), e3(); - T call(T t) => t + T call(T t) => t; } enum E2 { diff --git a/LanguageFeatures/Enhanced-Enum/semantics_A03_t01.dart b/LanguageFeatures/Enhanced-Enum/semantics_A03_t01.dart new file mode 100644 index 0000000000..d5ebaa556e --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/semantics_A03_t01.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2021, 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 If no generative constructors were declared, and no unnamed +/// factory constructor was added, a default generative constructor +/// const Name._$(this.index, this._$name); is added. +/// +/// @description Check the case when enum has no generative constructor +/// specified +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +import "../../Utils/expect.dart"; + +enum E1 { + e1, + e2, + e3; + + factory E1.f(int index) => values[i]; +} + +enum E2 { + e1(), + e2(), + e3(); + + factory E2.f(int index) => values[i]; +} + +main() { + Expect.equals(0, E1.e1.index); + Expect.equals(1, E1.e2.index); + Expect.equals(2, E1.e3.index); + Expect.equals("E1.e1", E1.e1.toString()); + Expect.equals("E1.e2", E1.e2.toString()); + Expect.equals("E1.e3", E1.e3.toString()); + Expect.equals(0, E2.e1.index); + Expect.equals(1, E2.e2.index); + Expect.equals(2, E2.e3.index); + Expect.equals("E2.e1", E2.e1.toString()); + Expect.equals("E2.e2", E2.e2.toString()); + Expect.equals("E2.e3", E2.e3.toString()); +} diff --git a/LanguageFeatures/Enhanced-Enum/semantics_A04_t01.dart b/LanguageFeatures/Enhanced-Enum/semantics_A04_t01.dart new file mode 100644 index 0000000000..ab00f49332 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/semantics_A04_t01.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2021, 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 If no toString member was declared, add +/// String toString() => “Name.${_$name}”;. +/// +/// @description Check that if no toString member was declared, then +/// String toString() => “Name.${_$name}”; is added. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +import "../../Utils/expect.dart"; + +enum E { + e1(42), + e2("42"), + e3(false); + + final T _t; + + const E(this._t); +} + +main() { + Expect.equals("E.e1", E.e1.toString()); + Expect.equals("E.e2", E.e2.toString()); + Expect.equals("E.e3", E.e3.toString()); +} diff --git a/LanguageFeatures/Enhanced-Enum/semantics_A04_t02.dart b/LanguageFeatures/Enhanced-Enum/semantics_A04_t02.dart new file mode 100644 index 0000000000..f489f53e13 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/semantics_A04_t02.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2021, 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 If no toString member was declared, add +/// String toString() => “Name.${_$name}”;. +/// +/// @description Check that if 'toString' member specified, then it is called +/// instead of the default one +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +import "../../Utils/expect.dart"; + +enum E1 { + e1, + e2, + e3; + + String toString() => "Enum E1.${this.name}"; +} + +enum E2 { + e1(42), + e2("Lily was here"), + e3(false); + + final T _t; + + const E2(this._t); + + String toString() => "E2<$T>.${this.name}($_t)"; +} + +main() { + Expect.equals("Enum E1.e1", E1.e1.toString()); + Expect.equals("Enum E1.e2", E1.e2.toString()); + Expect.equals("Enum E1.e3", E1.e3.toString()); + Expect.equals("E2.e1(42)", E2.e1.toString()); + Expect.equals("E2.e2(Lily was here)", E2.e2.toString()); + Expect.equals("E2.e3(false)", E2.e3.toString()); +} diff --git a/LanguageFeatures/Enhanced-Enum/semantics_A05_t01.dart b/LanguageFeatures/Enhanced-Enum/semantics_A05_t01.dart new file mode 100644 index 0000000000..fe5463fe2a --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/semantics_A05_t01.dart @@ -0,0 +1,45 @@ +// Copyright (c) 2021, 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 For each with name id and index i in the +/// comma-separated list of enum entries, a static constant is added as follows: +/// +/// id ↦ static const Name id = Name._$(i, "id"); — equivalent to id(). +/// id(args) ↦ static const Name id = Name._$(i, “id”, args); — if Name is not +/// generic +/// id(args) ↦ +/// static const Name id = Name._$(i, “id”, args); +/// id.named(args) ↦ static const Name id = Name._$named(i, “id”, args); — if +/// Name is not generic +/// id.named(args) ↦ +/// static const Name id = Name._$named(i, “id”, args); +/// +/// @description Check that it is a compile time error if member is called with +/// a wrong type +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E { + e1(), + e2(), + e3(); + + T foo(T t) => t; +} + +main() { + E.e1.foo("42"); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + E.e2.foo(42); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + E.e3.foo(42); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +}