diff --git a/LanguageFeatures/Static-extensions/syntax_A01_t01.dart b/LanguageFeatures/Static-extensions/syntax_A01_t01.dart new file mode 100644 index 0000000000..36f5743f9f --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A01_t01.dart @@ -0,0 +1,39 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// ... +/// For the purpose of identifying the on-declaration of a given extension, the +/// types `void`, `dynamic`, and `Never` are not considered to be classes, and +/// neither are record types or function types. +/// +/// @description Checks that that it is a compile-time error to declare a +/// factory constructor in an extension declaration that has no on-declaration. +/// Test extension on type `void`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +class C {} + +typedef Void = void; + +extension Ext on void { + factory Void.foo() => 42; +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + factory Void.bar() = C.new; +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A01_t02.dart b/LanguageFeatures/Static-extensions/syntax_A01_t02.dart new file mode 100644 index 0000000000..7666b5c19c --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A01_t02.dart @@ -0,0 +1,37 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// ... +/// For the purpose of identifying the on-declaration of a given extension, the +/// types `void`, `dynamic`, and `Never` are not considered to be classes, and +/// neither are record types or function types. +/// +/// @description Checks that that it is a compile-time error to declare a +/// factory constructor in an extension declaration that has no on-declaration. +/// Test extension on type `dynamic`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +class C {} + +extension Ext on dynamic { + factory dynamic.foo() => C(); +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + factory dynamic.bar() = C.new; +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A01_t03.dart b/LanguageFeatures/Static-extensions/syntax_A01_t03.dart new file mode 100644 index 0000000000..1b54acd7f0 --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A01_t03.dart @@ -0,0 +1,37 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// ... +/// For the purpose of identifying the on-declaration of a given extension, the +/// types `void`, `dynamic`, and `Never` are not considered to be classes, and +/// neither are record types or function types. +/// +/// @description Checks that that it is a compile-time error to declare a +/// factory constructor in an extension declaration that has no on-declaration. +/// Test extension on type `Never`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +class C {} + +extension Ext on Never { + factory Never.foo() => C(); +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + factory Never.bar() = C.new; +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A01_t04.dart b/LanguageFeatures/Static-extensions/syntax_A01_t04.dart new file mode 100644 index 0000000000..969b1fd439 --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A01_t04.dart @@ -0,0 +1,29 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// ... +/// For the purpose of identifying the on-declaration of a given extension, the +/// types `void`, `dynamic`, and `Never` are not considered to be classes, and +/// neither are record types or function types. +/// +/// @description Checks that that it is a compile-time error to declare a +/// factory constructor in an extension declaration that has no on-declaration. +/// Test extension on type `Record`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +extension Ext on Record { + factory Record.foo() => (); +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { +} diff --git a/LanguageFeatures/Static-extensions/syntax_A01_t05.dart b/LanguageFeatures/Static-extensions/syntax_A01_t05.dart new file mode 100644 index 0000000000..732cc4dd4b --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A01_t05.dart @@ -0,0 +1,32 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// ... +/// For the purpose of identifying the on-declaration of a given extension, the +/// types `void`, `dynamic`, and `Never` are not considered to be classes, and +/// neither are record types or function types. +/// +/// @description Checks that that it is a compile-time error to declare a +/// factory constructor in an extension declaration that has no on-declaration. +/// Test extension on a function type. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +typedef F = void Function(); + +extension Ext on F { + factory F.foo() => () {}; +//^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(F); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A02_t01.dart b/LanguageFeatures/Static-extensions/syntax_A02_t01.dart new file mode 100644 index 0000000000..fcc927af2f --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A02_t01.dart @@ -0,0 +1,43 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// +/// @description Checks that that it is not an error to declare a factory +/// constructor in an extension declaration that has an on-declaration. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +class C { + int v; + C(this.v); +} + +class D extends C { + D(super.v); +} + +extension type ET(int v) {} + +extension ExtC on C { + factory C.foo() => D(0); + + factory C.bar(int v) = C.new; +} + +extension ExtET on ET { + factory ET.baz(int v) = ET.new; +} + +main() { + Expect.equals(0, C.foo().v); + Expect.equals(1, C.bar(1).v); + Expect.equals(2, ET.baz(2).v); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A02_t02.dart b/LanguageFeatures/Static-extensions/syntax_A02_t02.dart new file mode 100644 index 0000000000..4e8a506de0 --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A02_t02.dart @@ -0,0 +1,43 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// +/// @description Checks that that it is not an error to declare a constant +/// factory constructor in an extension declaration that has an on-declaration. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +class C { + final int v; + const C(this.v); +} + +class D extends C { + const D(super.v); +} + +extension type const ET(int v) {} + +extension ExtC on C { + const factory C.foo() => const D(0); + + const factory C.bar(int v) = C.new; +} + +extension ExtET on ET { + const factory ET.baz(int v) = ET.new; +} + +main() { + Expect.equals(0, const C.foo().v); + Expect.equals(1, const C.bar(1).v); + Expect.equals(2, const ET.baz(2).v); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A02_t03.dart b/LanguageFeatures/Static-extensions/syntax_A02_t03.dart new file mode 100644 index 0000000000..45ad5d882a --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A02_t03.dart @@ -0,0 +1,37 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// +/// @description Checks that that it is not an error to declare a redirecting +/// generative constructor in an extension declaration that has an +/// on-declaration. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +class C { + int v; + C(this.v); +} + +extension type ET(int v) {} + +extension ExtC on C { + C.foo() : this(0); +} + +extension ExtET on ET { + ET.bar() : this(1); +} + +main() { + Expect.equals(0, C.foo().v); + Expect.equals(1, ET.bar().v); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A02_t04.dart b/LanguageFeatures/Static-extensions/syntax_A02_t04.dart new file mode 100644 index 0000000000..5bf2cbcb67 --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A02_t04.dart @@ -0,0 +1,49 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// +/// @description Checks that that it is not an error to declare a constant +/// redirecting generative constructor in an extension declaration that has an +/// on-declaration. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +class C { + final int v; + const C(this.v); +} + +extension type const ET(int v) {} + +enum E { + e0(0), e1.baz(); + + final int v; + const E(this.v); +} + +extension ExtC on C { + const C.foo() : this(0); +} + +extension ExtET on ET { + const ET.bar() : this(1); +} + +extension ExtE on E { + const E.baz() : this(2); +} + +main() { + Expect.equals(0, C.foo().v); + Expect.equals(1, ET.bar().v); + Expect.equals(2, E.e1.v); +} diff --git a/LanguageFeatures/Static-extensions/syntax_A02_t05.dart b/LanguageFeatures/Static-extensions/syntax_A02_t05.dart new file mode 100644 index 0000000000..7ea3f77dbb --- /dev/null +++ b/LanguageFeatures/Static-extensions/syntax_A02_t05.dart @@ -0,0 +1,33 @@ +// 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 It is no longer an error to declare a factory constructor, +/// redirecting or not, or a redirecting generative constructor in an extension +/// declaration that has an on-declaration (defined later in this section), and +/// both kinds can be constant or not. +/// +/// @description Checks that that it is not a compile-time error to declare a +/// non-constant constant redirecting generative constructor in an extension +/// declaration on an enum. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +enum E { + e0(0); + + final int v; + const E(this.v); +} + +extension ExtE on E { + E.baz() : this(1); +//^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E); +}