diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01.dart index a9b22d047f..168b3b895b 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01.dart @@ -4,11 +4,12 @@ /// @assertion It is a compile-time error if: /// ... -/// - The resulting constructor is not valid (has a redirecting initializer and -/// other initializers, multiple super initializers, etc). +/// - The resulting constructor is not valid (it has a redirection as well as +/// some initializer list elements, or it has multiple `super` initializers, +/// etc). /// /// @description Checks that it is a compile-time error if the resulting -/// constructor has a redirecting initializer and other initializers. +/// constructor has a redirecting initializer and initializer list elements. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=macros @@ -18,7 +19,7 @@ part 'augmenting_constructors_A06_t01_lib.dart'; class C { int x; C(this.x); - C.foo(): this(0); + C.foo() : this(0); //^^^^^ // [analyzer] unspecified // [cfe] unspecified diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01_lib.dart index d17f573d7a..4cc7346966 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t01_lib.dart @@ -4,11 +4,12 @@ /// @assertion It is a compile-time error if: /// ... -/// - The resulting constructor is not valid (has a redirecting initializer and -/// other initializers, multiple super initializers, etc). +/// - The resulting constructor is not valid (it has a redirection as well as +/// some initializer list elements, or it has multiple `super` initializers, +/// etc). /// /// @description Checks that it is a compile-time error if the resulting -/// constructor has a redirecting initializer and other initializers. +/// constructor has a redirecting initializer and initializer list elements. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=macros @@ -16,5 +17,5 @@ part of 'augmenting_constructors_A06_t01.dart'; augment class C { - augment C.foo(): x = 1; + augment C.foo() : x = 1; } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t02.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t02.dart new file mode 100644 index 0000000000..d668079313 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t02.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2024, 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 resulting constructor is not valid (it has a redirection as well as +/// some initializer list elements, or it has multiple super initializers, +/// etc). +/// +/// @description Checks that it is a compile-time error if the resulting +/// constructor has multiple super initializers. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +part 'augmenting_constructors_A06_t02_lib.dart'; + +class A { + int x; + A(this.x); +} + +class C extends A { + C() : super(0); +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t02_lib.dart new file mode 100644 index 0000000000..002827195f --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A06_t02_lib.dart @@ -0,0 +1,21 @@ +// Copyright (c) 2024, 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 resulting constructor is not valid (it has a redirection as well as +/// some initializer list elements, or it has multiple super initializers, +/// etc). +/// +/// @description Checks that it is a compile-time error if the resulting +/// constructor has multiple super initializers. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +part of 'augmenting_constructors_A06_t02.dart'; + +augment class C { + augment C() : super(1); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01.dart index e6580b290a..94fc1977f7 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01.dart @@ -3,9 +3,9 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A non-redirecting generative constructor marked `augment` may: -/// - Add or replace the body of the augmented constructor with a new body. -/// - If the augmenting constructor has an explicit block body, then that body -/// replaces any existing constructor body. +/// ... +/// - If the augmenting constructor has an explicit block body, then that body +/// replaces any existing constructor body. /// /// @description Checks that if the augmenting constructor has an explicit block /// body, then that body replaces any existing constructor body. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01_lib.dart index 2839810193..08a9eb7a45 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t01_lib.dart @@ -3,9 +3,9 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A non-redirecting generative constructor marked `augment` may: -/// - Add or replace the body of the augmented constructor with a new body. -/// - If the augmenting constructor has an explicit block body, then that body -/// replaces any existing constructor body. +/// ... +/// - If the augmenting constructor has an explicit block body, then that body +/// replaces any existing constructor body. /// /// @description Checks that if the augmenting constructor has an explicit block /// body, then that body replaces any existing constructor body. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02.dart index 1a613b4dd4..ca82545ecb 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02.dart @@ -4,8 +4,6 @@ /// @assertion A non-redirecting generative constructor marked `augment` may: /// - Add or replace the body of the augmented constructor with a new body. -/// - If the augmenting constructor has an explicit block body, then that body -/// replaces any existing constructor body. /// /// @description Checks that an augmenting constructor may add a body to an /// augmented constructor. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02_lib.dart index f4f7e6019f..58d9b6c728 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t02_lib.dart @@ -4,8 +4,6 @@ /// @assertion A non-redirecting generative constructor marked `augment` may: /// - Add or replace the body of the augmented constructor with a new body. -/// - If the augmenting constructor has an explicit block body, then that body -/// replaces any existing constructor body. /// /// @description Checks that an augmenting constructor may add a body to an /// augmented constructor. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03.dart index 4d588230c5..4b4b465ddd 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03.dart @@ -4,8 +4,6 @@ /// @assertion A non-redirecting generative constructor marked `augment` may: /// - Add or replace the body of the augmented constructor with a new body. -/// - If the augmenting constructor has an explicit block body, then that body -/// replaces any existing constructor body. /// /// @description Checks that it is a compile-time error to augment a default /// unnamed constructor (that doesn't exist during augmentation). diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03_lib.dart index 5854d9c541..3ed7718cb5 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A09_t03_lib.dart @@ -4,8 +4,6 @@ /// @assertion A non-redirecting generative constructor marked `augment` may: /// - Add or replace the body of the augmented constructor with a new body. -/// - If the augmenting constructor has an explicit block body, then that body -/// replaces any existing constructor body. /// /// @description Checks that it is a compile-time error to augment a default /// unnamed constructor (that doesn't exist during augmentation). diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01.dart index ee541fbc3e..e9b9f87e62 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01_lib.dart index 16970539df..888477fe91 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t01_lib.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02.dart index 9ea4d30dd4..1cade00b99 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02_lib.dart index 9bc484d970..d47314d47a 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t02_lib.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03.dart index 09a7d42da8..c0ea8dc60a 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03_lib.dart index 8322a9ff20..484026e854 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t03_lib.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04.dart index 3a564a4df1..50df759f6c 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04_lib.dart index aaf9db9ef7..26d975b332 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t04_lib.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05.dart index 415168195a..5a3c7afc31 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05_lib.dart index 2319a0a66c..c661fba16a 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A16_t05_lib.dart @@ -4,6 +4,7 @@ /// @assertion A non-redirecting factory constructor marked `augment` works in /// the same way as a normal function augmentation. +/// /// If it has a body, it replaces the body of the augmented constructor /// (if present), and it may invoke the augmented body by calling /// `augmented(arguments)`. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01.dart index 023d85df50..c7ba0a19f8 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A redirecting generative constructor marked `augment` adds its -/// redirecting initializer to the augmented constructors initializer list. +/// redirection to the augmented constructor. /// /// This converts it into a redirecting generative constructor, removing the /// potentially non-redirecting property of the constructor. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01_lib.dart index 27977c2286..1f02afc4d5 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t01_lib.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A redirecting generative constructor marked `augment` adds its -/// redirecting initializer to the augmented constructors initializer list. +/// redirection to the augmented constructor. /// /// This converts it into a redirecting generative constructor, removing the /// potentially non-redirecting property of the constructor. @@ -18,6 +18,6 @@ part of 'augmenting_constructors_A17_t01.dart'; augment class C { - augment C.foo(int x, {int y}): this(x, y); - augment C.bar(int x, {required int y}): this.foo(x, y: y); + augment C.foo(int x, {int y}) : this(x, y); + augment C.bar(int x, {required int y}) : this.foo(x, y: y); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02.dart index 7c6c91197d..b09aac0b31 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A redirecting generative constructor marked `augment` adds its -/// redirecting initializer to the augmented constructors initializer list. +/// redirection to the augmented constructor. /// /// This converts it into a redirecting generative constructor, removing the /// potentially non-redirecting property of the constructor. @@ -20,8 +20,8 @@ part 'augmenting_constructors_A17_t02_lib.dart'; class C { int x; C(this.x); - C.foo(int x): this(x + 1); - C.bar(int x): this(x + 1); + C.foo(int x) : this(x + 1); + C.bar(int x) : this(x + 1); } main() { diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02_lib.dart index 3953343e42..9610de404d 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A17_t02_lib.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A redirecting generative constructor marked `augment` adds its -/// redirecting initializer to the augmented constructors initializer list. +/// redirection to the augmented constructor. /// /// This converts it into a redirecting generative constructor, removing the /// potentially non-redirecting property of the constructor. @@ -17,5 +17,5 @@ part of 'augmenting_constructors_A17_t02.dart'; augment class C { - augment C.bar(int x): this.foo(x + 1); + augment C.bar(int x) : this.foo(x + 1); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01.dart index 398d4c3ac8..eeff368f3e 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if the augmented constructor has @@ -23,6 +24,21 @@ class C { C.bar({required this.y}); } +enum E { + e0(1, 2), e1.foo(3, y: 4), e2.bar(5, y: 6); + final int x, y; + const E(this.x, [this.y = 0]); + const E.foo(this.x, {this.y = 0}); + const E.bar(this.x, {required this.y}); +} + +extension type ET(int x) { + ET.foo(this.x); + ET.bar({required this.x}); +} + main() { print(C); + print(E); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01_lib.dart index df2db60639..980f0e16f0 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t01_lib.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if the augmented constructor has @@ -17,12 +18,35 @@ part of 'augmenting_constructors_A18_t01.dart'; augment class C { - augment C.foo(this.x, {this.y}): this(x); + augment C.foo(this.x, {this.y}) : this(x); // ^ // [analyzer] unspecified // [cfe] unspecified - augment C.bar({required this.y}): this.foo(0); + augment C.bar({required this.y}) : this.foo(0); // ^ // [analyzer] unspecified // [cfe] unspecified } + +augment enum E { + augment e0; + augment const E.foo(this.x, {this.y}) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment const E.bar(this.x, {required this.y}) : this.foo(0); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment ET.foo(this.x) : this(0); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment ET.bar({required this.x}) : this.new(1); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02.dart index 8f78db3cfd..7a774349e7 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if the augmented constructor has a @@ -19,10 +20,26 @@ part 'augmenting_constructors_A18_t02_lib.dart'; class C { int x, y; C(this.x, [this.y = 0]); - C.foo(int x, {int y = 0}): assert(x > 0); - C.bar({required int x}): x = x, y = 0; + C.foo(int x, {int y = 0}) : assert(x > 0); + C.bar({required int x}) : x = x, y = 0; +} + +enum E { + e0(0); + + final int x, y; + const E(this.x, [this.y = 0]); + const E.foo(int x, {int y = 0}) : assert(x > 0); + const E.bar({required int x}) : x = x, y = 0; +} + +extension type ET(int x) { + ET.foo(int x) : assert(x > 0); + ET.bar({required int x}) : x = x; } main() { print(C); + print(E); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02_lib.dart index 584d4ba8aa..38a3ad0d9a 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t02_lib.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if the augmented constructor has a @@ -17,12 +18,35 @@ part of 'augmenting_constructors_A18_t02.dart'; augment class C { - augment C.foo(int x, {int y = 0}): this(x); -// ^ + augment C.foo(int x, {int y = 0}) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment C.bar({required int x}) : this.foo(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment enum E { + augment e0; + augment const E.foo(int x, {int y = 0}) : this(x); +// ^ // [analyzer] unspecified // [cfe] unspecified - augment C.bar({required int x}): this.foo(x); -// ^ + augment const E.bar({required int x}) : this.foo(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment ET.foo(int x) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment ET.bar({required int x}) : this.new(x); +// ^ // [analyzer] unspecified // [cfe] unspecified } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03.dart index f7298c6cc9..2d4bc6a473 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if the augmented constructor has a super @@ -22,8 +23,8 @@ class A { } class C extends A { - C(): super(0); - C.foo(): super(0); + C() : super(0); + C.foo() : super(0); } main() { diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03_lib.dart index 8022b47aa5..11ede4a7ef 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t03_lib.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if the augmented constructor has a super diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04.dart index 22ee766cb3..075424703a 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04.dart @@ -5,16 +5,15 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// -/// @description Checks that it is not an error to declare an augmenting -/// redirecting generative constructor more than once and the fully merged -/// constructor has no errors. +/// @description Checks that it is a compile-time error to declare an augmenting +/// redirecting generative constructor more than once. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=macros -import '../../Utils/expect.dart'; part 'augmenting_constructors_A18_t04_lib.dart'; class C { @@ -23,6 +22,19 @@ class C { C.foo(int x); } +enum E { + e0(0), e1.foo(1); + final int x; + const E(this.x); + const E.foo(int x); +} + +extension type ET(int x) { + ET.foo(int x); +} + main() { - Expect.equals(2, C.foo(1)); + print(C); + print(E); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04_lib.dart index f89cc1c50d..1e8f05866b 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t04_lib.dart @@ -5,11 +5,11 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting -/// redirecting generative constructor if the augmented constructor has a -/// non-empty initializing list. +/// redirecting generative constructor more than once. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=macros @@ -17,6 +17,26 @@ part of 'augmenting_constructors_A18_t04.dart'; augment class C { - augment C.foo(int x): this.foo(x); // Cyclic! But it is fixed below - augment C.foo(int x): this(x + 1); // Not a cyclic now + augment C.foo(int x) : this(x + 1); // Ok + augment C.foo(int x) : this(x + 2); // Augmented constructor already has a redirection +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment enum E { + augment e0; + augment const E.foo(int x) : this(x + 1); + augment const E.foo(int x) : this(x + 2); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment ET.foo(int x) : this(x + 1); + augment ET.foo(int x) : this(x + 2); +// ^ +// [analyzer] unspecified +// [cfe] unspecified } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05.dart index b77beffc20..1b95430595 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error if a merged constructor /// is cyclic. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05_lib.dart index 0ceeec7e37..11a3c10c6d 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t05_lib.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error if a merged constructor /// is cyclic. diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06.dart index ade53e8a0a..6a389ff304 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if an introductory constructor has a body @@ -20,6 +21,11 @@ class C { C.foo() {} } +extension type ET(int x) { + ET.foo(int x) {} +} + main() { print(C); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06_lib.dart index 36c30ebc20..07bf95f6b8 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t06_lib.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting generative constructor if an introductory constructor has a body @@ -16,8 +17,15 @@ part of 'augmenting_constructors_A18_t06.dart'; augment class C { - augment C.foo(): this(); -// ^ + augment C.foo() : this(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment ET.foo(int x) : this(x); +// ^ // [analyzer] unspecified // [cfe] unspecified } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07.dart index f0f7e37c7a..d90f874a16 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error if a merged constructor /// is cyclic. @@ -21,6 +22,20 @@ class C { C.bar(); } +enum E { + e0; + const E(); + const E.foo(); + const E.bar(); +} + +extension type ET(int x) { + ET.foo(int x); + ET.bar(int x); +} + main() { print(C); + print(E); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07_lib.dart index acbd442083..a17af1bfe3 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A18_t07_lib.dart @@ -5,7 +5,8 @@ /// @assertion Redirecting generative constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has any initializers or a body. +/// - The augmented constructor has an initializer list or a body, or it has a +/// redirection. /// /// @description Checks that it is a compile-time error if a merged constructor /// is cyclic. @@ -29,3 +30,34 @@ augment class C { // [analyzer] unspecified // [cfe] unspecified } + +augment enum E { + augment e0; + augment const E(): this.foo(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment const E.foo(): this.bar(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment const E.bar(): this(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment ET.new(int x): this.foo(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment ET.foo(int x): this.bar(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment ET.bar(int x): this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01.dart index 5dfae14da1..7701563efd 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A redirecting factory constructor marked `augment` adds its -/// factory redirection to the augmented constructor. +/// factory redirection (e.g., `= C.name`) to the augmented constructor. /// /// The result of applying the augmenting constructor is a redirecting factory /// constructor with the same target constructor designation as the augmenting @@ -32,6 +32,12 @@ class D extends C { D(super.x, [super.y = 0]); } +extension type ET(int x) { + ET.foo(this.x); + factory ET.bar(int x); + factory ET.baz(int x); +} + main() { Expect.equals(1, C.bar(1).x); Expect.equals(0, C.bar(1).y); @@ -47,4 +53,7 @@ main() { Expect.equals(0, C.qux(1).y); Expect.equals(1, C.qux(1, 2).x); Expect.equals(2, C.qux(1, 2).y); + + Expect.equals(1, ET.bar(1).x); + Expect.equals(2, ET.baz(2).x); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01_lib.dart index 1beaa58cf6..c3751cdf88 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t01_lib.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. /// @assertion A redirecting factory constructor marked `augment` adds its -/// factory redirection to the augmented constructor. +/// factory redirection (e.g., `= C.name`) to the augmented constructor. /// /// The result of applying the augmenting constructor is a redirecting factory /// constructor with the same target constructor designation as the augmenting @@ -23,3 +23,8 @@ augment class C { augment factory C.baz(int x, {int y}) = C.foo; augment factory C.qux(int x, [int y]) = D; } + +augment extension type ET { + augment factory ET.bar(int x) = ET; + augment factory ET.baz(int x) = ET.foo; +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t02_lib.dart deleted file mode 100644 index a25c775366..0000000000 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t02_lib.dart +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2024, 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 A redirecting factory constructor marked `augment` adds its -/// factory redirection to the augmented constructor. -/// -/// The result of applying the augmenting constructor is a redirecting factory -/// constructor with the same target constructor designation as the augmenting -/// constructor. This removes the potentially non-redirecting property of the -/// constructor. -/// -/// @description Checks that it is not an error if an introductory constructor -/// already has a redirection. Test the same augmenting redirections. -/// @author sgrekhov22@gmail.com - -// SharedOptions=--enable-experiment=macros - -part of 'augmenting_constructors_A19_t02.dart'; - -augment class C { - augment factory C.bar(int x, [int y]) = C; - augment factory C.baz(int x, {int y}) = C.foo; - augment factory C.qux(int x, [int y]) = D; -} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t03_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t03_lib.dart deleted file mode 100644 index 94b6feaa77..0000000000 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t03_lib.dart +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2024, 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 A redirecting factory constructor marked `augment` adds its -/// factory redirection to the augmented constructor. -/// -/// The result of applying the augmenting constructor is a redirecting factory -/// constructor with the same target constructor designation as the augmenting -/// constructor. This removes the potentially non-redirecting property of the -/// constructor. -/// -/// @description Checks that it is not an error if an introductory constructor -/// already has a redirection. -/// @author sgrekhov22@gmail.com - -// SharedOptions=--enable-experiment=macros - -part of 'augmenting_constructors_A19_t03.dart'; - -augment class C { - augment factory C.bar(int x, [int y]) = D; - augment factory C.baz(int x, {int y}) = D.foo; - augment factory C.qux(int x, [int y]) = C; -} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01.dart index 70d1c64153..7a9bcd5b4e 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error if the augmented /// constructor has a body. @@ -28,7 +28,14 @@ class D extends C { D(super.x, [super.y = 0]); } +extension type ET(int x) { + ET.foo(this.x); + factory ET.bar(int x) => ET(x); + factory ET.baz(int x) => ET.foo(x); +} + main() { print(C); print(D); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01_lib.dart index 1d572bc8c8..97daeff3ca 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t01_lib.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error if the augmented /// constructor has a body. @@ -29,3 +29,14 @@ augment class C { // [analyzer] unspecified // [cfe] unspecified } + +augment extension type ET { + augment factory ET.bar(int x) = ET; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory ET.baz(int x) = ET.foo; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02.dart index f88569c03a..3d99c2e37f 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error if the augmenting /// constructor references itself. @@ -24,6 +24,11 @@ class C { factory C.qux({required int x}); } +extension type ET(int x) { + factory ET.foo(int x); +} + main() { print(C); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02_lib.dart index 20fbced2f3..e3bf108126 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t02_lib.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error if the augmenting /// constructor references itself. @@ -33,3 +33,11 @@ augment class C { // [analyzer] unspecified // [cfe] unspecified } + + +augment extension type ET { + augment factory ET(int x) = ET.foo; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03.dart index f645234cb3..9ae964c527 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error if the augmenting /// constructor indirectly references itself. @@ -21,6 +21,12 @@ class C { factory C.bar(); } +extension type ET(int x) { + factory ET.foo(int x); + factory ET.bar(int x); +} + main() { print(C); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03_lib.dart index 287e7c5ef2..c13236e08f 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t03_lib.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error if the augmenting /// constructor indirectly references itself. @@ -29,3 +29,17 @@ augment class C { // [analyzer] unspecified // [cfe] unspecified } + +augment extension type ET { + augment factory ET(int x) = ET.bar; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory ET.foo(int x) = ET; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + // ^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04.dart index 01b4bf85b2..ea98832ab1 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting factory constructor if an introductory constructor has any @@ -24,6 +24,14 @@ class C { factory C.baz({int x = 0}); } +extension type ET(int x) { + ET.foo([this.x = 0]); + ET.bar({this.x = 0}); + factory ET.baz([int x = 0]); + factory ET.qux({int x = 0}); +} + main() { print(C); + print(ET); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04_lib.dart index 6e9e693ebf..99d60bdaf2 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04_lib.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t04_lib.dart @@ -5,7 +5,7 @@ /// @assertion Redirecting factory constructors /// ... /// It is a compile-time error if: -/// - The augmented constructor has a body. +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is a compile-time error to declare an augmenting /// redirecting factory constructor if an introductory constructor has any @@ -26,3 +26,14 @@ augment class C { // [analyzer] unspecified // [cfe] unspecified } + +augment extension type ET { + augment factory ET.baz([int x = 0]) = ET; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory ET.qux({int x = 0}) = ET.foo; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t02.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t05.dart similarity index 63% rename from LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t02.dart rename to LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t05.dart index 452ae1eee5..5b2115f971 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t02.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t05.dart @@ -2,22 +2,19 @@ // 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 A redirecting factory constructor marked `augment` adds its -/// factory redirection to the augmented constructor. +/// @assertion Redirecting factory constructors +/// ... +/// It is a compile-time error if: +/// - The augmented factory constructor has a body, or it is redirecting. /// -/// The result of applying the augmenting constructor is a redirecting factory -/// constructor with the same target constructor designation as the augmenting -/// constructor. This removes the potentially non-redirecting property of the -/// constructor. -/// -/// @description Checks that it is not an error if an introductory constructor -/// already has a redirection. Test the same augmenting redirections. +/// @description Checks that it is a compile-time error if an introductory +/// constructor already has a redirection. Test the same augmenting redirections /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=macros import '../../Utils/expect.dart'; -part 'augmenting_constructors_A19_t02_lib.dart'; +part 'augmenting_constructors_A20_t05_lib.dart'; class C { int x, y; @@ -32,6 +29,12 @@ class D extends C { D(super.x, [super.y = 0]); } +extension type ET(int x) { + ET.foo(this.x); + factory ET.bar(int x) = ET; + factory ET.baz(int x) = ET.foo; +} + main() { Expect.equals(1, C.bar(1).x); Expect.equals(0, C.bar(1).y); @@ -47,4 +50,7 @@ main() { Expect.equals(0, C.qux(1).y); Expect.equals(1, C.qux(1, 2).x); Expect.equals(2, C.qux(1, 2).y); + + Expect.equals(1, ET.bar(1).x); + Expect.equals(2, ET.baz(2).x); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t05_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t05_lib.dart new file mode 100644 index 0000000000..9234c91384 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t05_lib.dart @@ -0,0 +1,42 @@ +// Copyright (c) 2024, 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 Redirecting factory constructors +/// ... +/// It is a compile-time error if: +/// - The augmented factory constructor has a body, or it is redirecting. +/// +/// @description Checks that it is a compile-time error if an introductory +/// constructor already has a redirection. Test the same augmenting redirections +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +part of 'augmenting_constructors_A20_t05.dart'; + +augment class C { + augment factory C.bar(int x, [int y]) = C; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory C.baz(int x, {int y}) = C.foo; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory C.qux(int x, [int y]) = D; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment factory ET.bar(int x) = ET; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory ET.baz(int x) = ET.foo; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t03.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t06.dart similarity index 72% rename from LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t03.dart rename to LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t06.dart index 0bb18879f6..795ed4e98f 100644 --- a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A19_t03.dart +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t06.dart @@ -2,13 +2,10 @@ // 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 A redirecting factory constructor marked `augment` adds its -/// factory redirection to the augmented constructor. -/// -/// The result of applying the augmenting constructor is a redirecting factory -/// constructor with the same target constructor designation as the augmenting -/// constructor. This removes the potentially non-redirecting property of the -/// constructor. +/// @assertion Redirecting factory constructors +/// ... +/// It is a compile-time error if: +/// - The augmented factory constructor has a body, or it is redirecting. /// /// @description Checks that it is not an error if an introductory constructor /// already has a redirection. @@ -17,7 +14,7 @@ // SharedOptions=--enable-experiment=macros import '../../Utils/expect.dart'; -part 'augmenting_constructors_A19_t03_lib.dart'; +part 'augmenting_constructors_A20_t06_lib.dart'; class C { int x, y; @@ -33,6 +30,12 @@ class D extends C { D.foo(int x, {int y = 1}): super(x, y); } +extension type ET(int x) { + ET.foo(this.x); + factory ET.bar(int x) = ET; + factory ET.baz(int x) = ET.foo; +} + main() { Expect.equals(1, C.bar(1).x); Expect.equals(1, C.bar(1).y); @@ -48,4 +51,7 @@ main() { Expect.equals(0, C.qux(1).y); Expect.equals(1, C.qux(1, 2).x); Expect.equals(2, C.qux(1, 2).y); + + Expect.equals(1, ET.bar(1).x); + Expect.equals(2, ET.baz(2).x); } diff --git a/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t06_lib.dart b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t06_lib.dart new file mode 100644 index 0000000000..9738b40d1d --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmenting_constructors_A20_t06_lib.dart @@ -0,0 +1,42 @@ +// Copyright (c) 2024, 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 Redirecting factory constructors +/// ... +/// It is a compile-time error if: +/// - The augmented factory constructor has a body, or it is redirecting. +/// +/// @description Checks that it is a compile-time error if an introductory +/// constructor already has a redirection. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +part of 'augmenting_constructors_A20_t06.dart'; + +augment class C { + augment factory C.bar(int x, [int y]) = D; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory C.baz(int x, {int y}) = D.foo; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory C.qux(int x, [int y]) = C; +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment factory ET.bar(int x) = ET.foo; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory ET.baz(int x) = ET; +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +}