| // Copyright (c) 2026, 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 Given a constructor declaration in an extension which declares a | |
| /// named constructor with name `Name`, it is an error if `Name` is either the | |
| /// name of the extension, or the on-declaration of the extension | |
| /// | |
| /// @description Checks that it is a compile-time error if an extension declares | |
| /// a redirecting factory constructor whose name is the name of the | |
| /// on-declaration of the extension. Test unnamed extensions. | |
| /// @author sgrekhov22@gmail.com | |
| // SharedOptions=--enable-experiment=static-extensions | |
| class C { | |
| C.someName(); | |
| } | |
| extension on C { | |
| factory C() = C.someName; | |
| // ^ | |
| // [analyzer] unspecified | |
| // [cfe] unspecified | |
| } | |
| mixin M {} | |
| extension on M { | |
| factory M() = MO.new; | |
| // ^ | |
| // [analyzer] unspecified | |
| // [cfe] unspecified | |
| } | |
| class MO = Object with M; | |
| mixin class MC { | |
| MC.someName(); | |
| } | |
| extension on MC { | |
| factory MC() = MC.someName; | |
| // ^^ | |
| // [analyzer] unspecified | |
| // [cfe] unspecified | |
| } | |
| extension type ET.someName(int _) {} | |
| extension on ET { | |
| factory ET(int v) = ET.someName; | |
| // ^^ | |
| // [analyzer] unspecified | |
| // [cfe] unspecified | |
| } | |
| class G<T> { | |
| G.someName(); | |
| } | |
| extension<T> on G<T> { | |
| factory G() = G<T>.someName; | |
| // ^ | |
| // [analyzer] unspecified | |
| // [cfe] unspecified | |
| } | |
| class CC { | |
| const CC.someName(); | |
| } | |
| extension on CC { | |
| const factory CC() = CC.someName; | |
| // ^^ | |
| // [analyzer] unspecified | |
| // [cfe] unspecified | |
| } | |
| // No enum type here we because can't have a redirecting constructor whose | |
| // return type is an enumerated type | |
| main() { | |
| print(C); | |
| print(M); | |
| print(MC); | |
| print(ET); | |
| print(G); | |
| print(CC); | |
| } |