Skip to content
Merged
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
68 changes: 68 additions & 0 deletions LanguageFeatures/Static-extensions/static_member_A03_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 Consider an expression `e` which is a member invocation with
/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is
/// a static member declared by `D`. The static analysis and dynamic semantics
/// of this expression is the same as in Dart before the introduction of this
/// feature.
///
/// @description Checks that if `C` contains a static member with the basename
/// `m` then it is not an error for extensions to declare a static member with
/// the same basename. Invocation of `m` will invoke the `on` declaration member
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=static-extensions

import '../../Utils/expect.dart';

String log = "";

class C {
static int foo = 42;
}

mixin M {
static int foo() => 42;
}

extension type ET(int _) {
static int get foo => 42;
}

enum E {
e0;
static void set foo(int v) {
log = "$v";
}
}

extension ExtC on C {
static String foo() => "ExtC";
}

extension ExtM on M {
static String foo() => "ExtM";
}

extension ExtET on ET {
static String foo() => "ExtET";
}

extension ExtE on E {
static String foo() => "ExtE";
}

main() {
Expect.equals(42, C.foo);
Expect.equals(42, M.foo());
Expect.equals(42, ET.foo);
E.foo = 42;
Expect.equals("42", log);

Expect.equals("ExtC", ExtC.foo());
Expect.equals("ExtM", ExtM.foo());
Expect.equals("ExtET", ExtET.foo());
Expect.equals("ExtE", ExtE.foo());
}
70 changes: 70 additions & 0 deletions LanguageFeatures/Static-extensions/static_member_A03_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 Consider an expression `e` which is a member invocation with
/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is
/// a static member declared by `D`. The static analysis and dynamic semantics
/// of this expression is the same as in Dart before the introduction of this
/// feature.
///
/// @description Checks that if `C` contains a static member with the basename
/// `m` then it is not an error for extensions to declare a static member with
/// the same basename. Invocation of `m` will invoke the `on` declaration member
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=static-extensions

import '../../Utils/expect.dart';

String log = "";

class C {
int foo = 42;
}

mixin M {
int foo() => 42;
}

class MA = Object with M;

extension type ET(int _) {
int get foo => 42;
}

enum E {
e0;
void set foo(int v) {
log = "$v";
}
}

extension ExtC on C {
static String foo() => "ExtC";
}

extension ExtM on M {
static String foo() => "ExtM";
}

extension ExtET on ET {
static String foo() => "ExtET";
}

extension ExtE on E {
static String foo() => "ExtE";
}

main() {
Expect.equals(42, C().foo);
Expect.equals(42, MA().foo());
Expect.equals(42, ET(0).foo);
E.e0.foo = 42;
Expect.equals("42", log);

Expect.equals("ExtC", ExtC.foo());
Expect.equals("ExtM", ExtM.foo());
Expect.equals("ExtET", ExtET.foo());
Expect.equals("ExtE", ExtE.foo());
}
72 changes: 72 additions & 0 deletions LanguageFeatures/Static-extensions/static_member_A04_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 Consider an expression `e` which is a member invocation with
/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is
/// a static member declared by `D`. The static analysis and dynamic semantics
/// of this expression is the same as in Dart before the introduction of this
/// feature.
/// ...
/// When `D` declares a static member whose basename is the basename of `m`, but
/// `D` does not declare a static member named `m` or a constructor named `C.m`,
/// a compile-time error occurs.
///
/// @description Checks that it is a compile-time error if `D` declares a static
/// member whose basename is the basename of `m`, but `D` does not declare a
/// member named `m`
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=static-extensions

class C {
static final int foo = 42;
}

mixin M {
static int foo() => 42;
}

extension type ET(int _) {
static int get foo => 42;
}

enum E {
e0;
static int foo() => 42;
}

extension ExtC on C {
static void set foo(int _) {}
}

extension ExtM on M {
static void set foo(int _) {}
}

extension ExtET on ET {
static void set foo(int _) {}
}

extension ExtE on E {
static void set foo(int _) {}
}

main() {
C.foo = 42;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
M.foo = 42;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
ET.foo = 42;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
E.foo = 42;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}
72 changes: 72 additions & 0 deletions LanguageFeatures/Static-extensions/static_member_A04_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 Consider an expression `e` which is a member invocation with
/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is
/// a static member declared by `D`. The static analysis and dynamic semantics
/// of this expression is the same as in Dart before the introduction of this
/// feature.
/// ...
/// When `D` declares a static member whose basename is the basename of `m`, but
/// `D` does not declare a static member named `m` or a constructor named `C.m`,
/// a compile-time error occurs.
///
/// @description Checks that it is a compile-time error if `D` declares a static
/// member whose basename is the basename of `m`, but `D` does not declare a
/// member named `m`
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=static-extensions

class C {
static void set foo(int _) {}
}

mixin M {
static void set foo(int _) {}
}

extension type ET(int _) {
static void set foo(int _) {}
}

enum E {
e0;
static void set foo(int _) {}
}

extension ExtC on C {
static final int foo = 42;
}

extension ExtM on M {
static int foo() => 42;
}

extension ExtET on ET {
static int get foo => 42;
}

extension ExtE on E {
static int get foo => 42;
}

main() {
C.foo;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
M.foo();
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
ET.foo;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
E.foo;
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}
58 changes: 58 additions & 0 deletions LanguageFeatures/Static-extensions/static_member_A05_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 Consider an expression `e` which is a member invocation with
/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is
/// a static member declared by `D`. The static analysis and dynamic semantics
/// of this expression is the same as in Dart before the introduction of this
/// feature.
/// ...
/// Assume that it is an extension `E` that declares a static member named `m`.
/// The invocation is then treated as `E.m()`.
///
/// @description Checks that invocation of `m` is then treated as `E.m()`. Test
/// a static variable as `m`.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=static-extensions

import '../../Utils/expect.dart';

class C {}

mixin M {}

extension type ET(int _) {}

enum E {
e0;
}

extension ExtC on C {
static String foo = "ExtC";
}

extension ExtM on M {
static String foo = "ExtM";
}

extension ExtET on ET {
static String foo = "ExtET";
}

extension ExtE on E {
static String foo = "ExtE";
}

main() {
Expect.equals("ExtC", C.foo);
Expect.equals("ExtM", M.foo);
Expect.equals("ExtET", ET.foo);
Expect.equals("ExtE", E.foo);

Expect.equals("ExtC", ExtC.foo);
Expect.equals("ExtM", ExtM.foo);
Expect.equals("ExtET", ExtET.foo);
Expect.equals("ExtE", ExtE.foo);
}
Loading