Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -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);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -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);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -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);
}
29 changes: 29 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -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() {
}
32 changes: 32 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A01_t05.dart
Original file line number Diff line number Diff line change
@@ -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);
}
43 changes: 43 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -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);
}
43 changes: 43 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -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);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A02_t03.dart
Original file line number Diff line number Diff line change
@@ -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);
}
49 changes: 49 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A02_t04.dart
Original file line number Diff line number Diff line change
@@ -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);
}
33 changes: 33 additions & 0 deletions LanguageFeatures/Static-extensions/syntax_A02_t05.dart
Original file line number Diff line number Diff line change
@@ -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);
}