From 0b717811954795e351a2df0aec8518a44bb5a1b1 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Mon, 27 Jan 2025 11:21:46 +0200 Subject: [PATCH] #2162. Add static member and non-redirecting factory constructor conflict test --- .../static_member_and_constructor_t04.dart | 3 +- .../static_member_and_constructor_t05.dart | 92 +++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t05.dart diff --git a/Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t04.dart b/Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t04.dart index 192b4dd25e..7e35484d5c 100644 --- a/Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t04.dart +++ b/Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t04.dart @@ -6,7 +6,8 @@ /// constructor named `C.n` and a static member with basename `n`. /// /// @description Check that it is a compile-time error if class `C` declares a -/// factory constructor named `C.n` and a static member with basename `n`. +/// redirecting factory constructor named `C.n` and a static member with +/// basename `n`. /// @author sgrekhov22@gmail.com class C { diff --git a/Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t05.dart b/Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t05.dart new file mode 100644 index 0000000000..3d4cfb26e7 --- /dev/null +++ b/Language/Classes/Class_Member_Conflicts/static_member_and_constructor_t05.dart @@ -0,0 +1,92 @@ +// Copyright (c) 2025, 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 Let `C` be a class. It is a compile-time error if `C` declares a +/// constructor named `C.n` and a static member with basename `n`. +/// +/// @description Check that it is a compile-time error if class `C` declares a +/// non-redirecting factory constructor named `C.n` and a static member with +/// basename `n`. +/// @author sgrekhov22@gmail.com + +class C { + C(); + + factory C.s1() => C(); +// ^^ +// [analyzer] unspecified + static set s1(var value) {} +// ^^ +// [cfe] unspecified + + factory C.s2() => C(); +// ^^ +// [analyzer] unspecified + static void s2() {} +// ^^ +// [cfe] unspecified + + factory C.s3() => C(); +// ^^ +// [analyzer] unspecified + static int s3() => 1; +// ^^ +// [cfe] unspecified + + factory C.s4() => C(); +// ^^ +// [analyzer] unspecified + static int get s4 => 1; +// ^^ +// [cfe] unspecified + + factory C.s5() => C(); +// ^^ +// [analyzer] unspecified + static int s5 = 1; +// ^^ +// [cfe] unspecified +} + +extension type ET(int n) { + factory ET.s1(int n) => ET(n); +// ^^ +// [analyzer] unspecified + static set s1(var _) {} +// ^^ +// [cfe] unspecified + + factory ET.s2(int n) => ET(n); +// ^^ +// [analyzer] unspecified + static void s2() {} +// ^^ +// [cfe] unspecified + + factory ET.s3(int n) => ET(n); +// ^^ +// [analyzer] unspecified + static int s3() => 1; +// ^^ +// [cfe] unspecified + + factory ET.s4(int n) => ET(n); +// ^^ +// [analyzer] unspecified + static int get s4 => 1; +// ^^ +// [cfe] unspecified + + factory ET.s5(int n) => ET(n); +// ^^ +// [analyzer] unspecified + static int s5 = 1; +// ^^ +// [cfe] unspecified +} + +main() { + print(C); + print(ET); +}