From b73fbfa3a08d029ddf114691edd506afe5f2fe0a Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Fri, 7 Nov 2025 13:39:19 +0200 Subject: [PATCH 1/2] #3330. Add test for the lexical lookup --- .../lexical_lookup_A01_t01.dart | 97 ++++++++++++++ .../lexical_lookup_A01_t02.dart | 97 ++++++++++++++ .../lexical_lookup_A01_t03.dart | 97 ++++++++++++++ .../lexical_lookup_A01_t04.dart | 123 ++++++++++++++++++ .../static_member_A01_t01.dart | 2 +- .../static_member_A02_t01.dart | 4 +- .../static_member_A02_t02.dart | 4 +- .../static_member_A02_t03.dart | 4 +- .../static_member_A02_t04.dart | 4 +- .../static_member_A02_t05.dart | 4 +- .../static_member_A02_t06.dart | 4 +- .../static_member_A02_t07.dart | 4 +- .../static_member_A02_t08.dart | 4 +- 13 files changed, 431 insertions(+), 17 deletions(-) create mode 100644 LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart create mode 100644 LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart create mode 100644 LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart create mode 100644 LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart new file mode 100644 index 0000000000..6b2b20ee32 --- /dev/null +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart @@ -0,0 +1,97 @@ +// 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 In addition to the member invocations specified above, it is also +/// possible to invoke a static member of the enclosing declaration based on +/// lexical lookup. This case is applicable when an expression in an extension +/// declaration resolves to an invocation of a static member of the enclosing +/// extension. +/// +/// @description Checks that a static member of an extension can be invoked if +/// an expression in an extension declaration resolves to an invocation of a +/// static member of the enclosing extension. Test a static variable invocation. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +class C { + static String foo = "C"; + + void test() { + Expect.equals("C", foo); + } +} + +mixin M { + static String foo = "M"; + + void test() { + Expect.equals("M", foo); + } +} + +extension type ET(int _) { + static String foo = "ET"; + + void test() { + Expect.equals("ET", foo); + } +} + +enum E { + e0; + static String foo = "E"; + + void test() { + Expect.equals("E", foo); + } +} + +extension ExtC on C { + static String foo = "ExtC"; + + void testExtension() { + Expect.equals("ExtC", foo); + } +} + +extension ExtM on M { + static String foo = "ExtM"; + + void testExtension() { + Expect.equals("ExtM", foo); + } +} + +extension ExtET on ET { + static String foo = "ExtET"; + + void testExtension() { + Expect.equals("ExtET", foo); + } +} + +extension ExtE on E { + static String foo = "ExtET"; + + void testExtension() { + Expect.equals("ExtET", foo); + } +} + +class MA = Object with M; + +main() { + C().test(); + MA().test(); + ET(0).test(); + E.e0.test(); + + C().testExtension(); + MA().testExtension(); + ET(0).testExtension(); + E.e0.testExtension(); +} diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart new file mode 100644 index 0000000000..9661f88f9f --- /dev/null +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart @@ -0,0 +1,97 @@ +// 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 In addition to the member invocations specified above, it is also +/// possible to invoke a static member of the enclosing declaration based on +/// lexical lookup. This case is applicable when an expression in an extension +/// declaration resolves to an invocation of a static member of the enclosing +/// extension. +/// +/// @description Checks that a static member of an extension can be invoked if +/// an expression in an extension declaration resolves to an invocation of a +/// static member of the enclosing extension. Test a static getter invocation. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +class C { + static String get foo => "C"; + + void test() { + Expect.equals("C", foo); + } +} + +mixin M { + static String get foo => "M"; + + void test() { + Expect.equals("M", foo); + } +} + +extension type ET(int _) { + static String get foo => "ET"; + + void test() { + Expect.equals("ET", foo); + } +} + +enum E { + e0; + static String get foo => "E"; + + void test() { + Expect.equals("E", foo); + } +} + +extension ExtC on C { + static String get foo => "ExtC"; + + void testExtension() { + Expect.equals("ExtC", foo); + } +} + +extension ExtM on M { + static String get foo => "ExtM"; + + void testExtension() { + Expect.equals("ExtM", foo); + } +} + +extension ExtET on ET { + static String get foo => "ExtET"; + + void testExtension() { + Expect.equals("ExtET", foo); + } +} + +extension ExtE on E { + static String foo = "ExtET"; + + void testExtension() { + Expect.equals("ExtET", foo); + } +} + +class MA = Object with M; + +main() { + C().test(); + MA().test(); + ET(0).test(); + E.e0.test(); + + C().testExtension(); + MA().testExtension(); + ET(0).testExtension(); + E.e0.testExtension(); +} diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart new file mode 100644 index 0000000000..89c9c6f5da --- /dev/null +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart @@ -0,0 +1,97 @@ +// 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 In addition to the member invocations specified above, it is also +/// possible to invoke a static member of the enclosing declaration based on +/// lexical lookup. This case is applicable when an expression in an extension +/// declaration resolves to an invocation of a static member of the enclosing +/// extension. +/// +/// @description Checks that a static member of an extension can be invoked if +/// an expression in an extension declaration resolves to an invocation of a +/// static member of the enclosing extension. Test a static method invocation. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +class C { + static String foo() => "C"; + + void test() { + Expect.equals("C", foo()); + } +} + +mixin M { + static String foo() => "M"; + + void test() { + Expect.equals("M", foo()); + } +} + +extension type ET(int _) { + static String foo() => "ET"; + + void test() { + Expect.equals("ET", foo()); + } +} + +enum E { + e0; + static String foo() => "E"; + + void test() { + Expect.equals("E", foo()); + } +} + +extension ExtC on C { + static String foo() => "ExtC"; + + void testExtension() { + Expect.equals("ExtC", foo()); + } +} + +extension ExtM on M { + static String foo() => "ExtM"; + + void testExtension() { + Expect.equals("ExtM", foo()); + } +} + +extension ExtET on ET { + static String foo() => "ExtET"; + + void testExtension() { + Expect.equals("ExtET", foo()); + } +} + +extension ExtE on E { + static String foo() => "ExtE"; + + void testExtension() { + Expect.equals("ExtE", foo()); + } +} + +class MA = Object with M; + +main() { + C().test(); + MA().test(); + ET(0).test(); + E.e0.test(); + + C().testExtension(); + MA().testExtension(); + ET(0).testExtension(); + E.e0.testExtension(); +} diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart new file mode 100644 index 0000000000..8cae18175a --- /dev/null +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart @@ -0,0 +1,123 @@ +// 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 In addition to the member invocations specified above, it is also +/// possible to invoke a static member of the enclosing declaration based on +/// lexical lookup. This case is applicable when an expression in an extension +/// declaration resolves to an invocation of a static member of the enclosing +/// extension. +/// +/// @description Checks that a static member of an extension can be invoked if +/// an expression in an extension declaration resolves to an invocation of a +/// static member of the enclosing extension. Test a static setter invocation. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=static-extensions + +import '../../Utils/expect.dart'; + +String log = ""; + +class C { + static void set foo(String v) { + log = "C:$v"; + } + + void test() { + foo = "a"; + Expect.equals("C:a", log); + } +} + +mixin M { + static void set foo(String v) { + log = "M:$v"; + } + + void test() { + foo = "b"; + Expect.equals("M:b", log); + } +} + +extension type ET(int _) { + static void set foo(String v) { + log = "ET:$v"; + } + + void test() { + foo = "c"; + Expect.equals("ET:c", log); + } +} + +enum E { + e0; + static void set foo(String v) { + log = "E:$v"; + } + + void test() { + foo = "d"; + Expect.equals("E:d", log); + } +} + +extension ExtC on C { + static void set foo(String v) { + log = "ExtC:$v"; + } + + void testExtension() { + foo = "a"; + Expect.equals("ExtC:a", log); + } +} + +extension ExtM on M { + static void set foo(String v) { + log = "ExtM:$v"; + } + + void testExtension() { + foo = "b"; + Expect.equals("ExtM:b", log); + } +} + +extension ExtET on ET { + static void set foo(String v) { + log = "ExtET:$v"; + } + + void testExtension() { + foo = "c"; + Expect.equals("ExtET:c", log); + } +} + +extension ExtE on E { + static void set foo(String v) { + log = "ExtE:$v"; + } + + void testExtension() { + foo = "d"; + Expect.equals("ExtE:d", log); + } +} + +class MA = Object with M; + +main() { + C().test(); + MA().test(); + ET(0).test(); + E.e0.test(); + + C().testExtension(); + MA().testExtension(); + ET(0).testExtension(); + E.e0.testExtension(); +} diff --git a/LanguageFeatures/Static-extensions/static_member_A01_t01.dart b/LanguageFeatures/Static-extensions/static_member_A01_t01.dart index 1baab9014f..5937bd3886 100644 --- a/LanguageFeatures/Static-extensions/static_member_A01_t01.dart +++ b/LanguageFeatures/Static-extensions/static_member_A01_t01.dart @@ -16,7 +16,7 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is a compile-time error if `M` is empty. +/// @description Checks that it is a compile-time error if `M` is empty. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t01.dart b/LanguageFeatures/Static-extensions/static_member_A02_t01.dart index 342e23c7d0..2322af6646 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t01.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t01.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is a compile-time error to invoke `m` if -/// `M` contains more than one member. Test a variable as `m`. +/// @description Checks that it is a compile-time error to invoke `m` if `M` +/// contains more than one member. Test a variable as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t02.dart b/LanguageFeatures/Static-extensions/static_member_A02_t02.dart index b3f7086cbe..3699f865b8 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t02.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t02.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is a compile-time error to invoke `m` if -/// `M` contains more than one member. Test a getter as `m`. +/// @description Checks that it is a compile-time error to invoke `m` if `M` +/// contains more than one member. Test a getter as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t03.dart b/LanguageFeatures/Static-extensions/static_member_A02_t03.dart index 1cd041978d..dfa4c79293 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t03.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t03.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is a compile-time error to invoke `m` if -/// `M` contains more than one member. Test a method as `m`. +/// @description Checks that it is a compile-time error to invoke `m` if `M` +/// contains more than one member. Test a method as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t04.dart b/LanguageFeatures/Static-extensions/static_member_A02_t04.dart index 0307e6eb03..f078d8d44a 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t04.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t04.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is a compile-time error to invoke `m` if -/// `M` contains more than one member. Test a setter as `m`. +/// @description Checks that it is a compile-time error to invoke `m` if `M` +/// contains more than one member. Test a setter as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t05.dart b/LanguageFeatures/Static-extensions/static_member_A02_t05.dart index 74765ecc38..b9a65be6ff 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t05.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t05.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is not an error if `M` contains more than -/// one member but `m` is not invoked. Test a variable as `m`. +/// @description Checks that it is not an error if `M` contains more than one +/// member but `m` is not invoked. Test a variable as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t06.dart b/LanguageFeatures/Static-extensions/static_member_A02_t06.dart index 513b9f0f43..01e99b7583 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t06.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t06.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is not an error if `M` contains more than -/// one member but `m` is not invoked. Test a getter as `m`. +/// @description Checks that it is not an error if `M` contains more than one +/// member but `m` is not invoked. Test a getter as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t07.dart b/LanguageFeatures/Static-extensions/static_member_A02_t07.dart index eecb57a8bb..5dda5a5bb7 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t07.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t07.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is not an error if `M` contains more than -/// one member but `m` is not invoked. Test a method as `m`. +/// @description Checks that it is not an error if `M` contains more than one +/// member but `m` is not invoked. Test a method as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/static_member_A02_t08.dart b/LanguageFeatures/Static-extensions/static_member_A02_t08.dart index 224b0d8eb9..4f09a809cd 100644 --- a/LanguageFeatures/Static-extensions/static_member_A02_t08.dart +++ b/LanguageFeatures/Static-extensions/static_member_A02_t08.dart @@ -16,8 +16,8 @@ /// ... /// An error occurs if `M` is empty, or `M` contains more than one member. /// -/// @description Checks that that it is not an error if `M` contains more than -/// one member but `m` is not invoked. Test a setter as `m`. +/// @description Checks that it is not an error if `M` contains more than one +/// member but `m` is not invoked. Test a setter as `m`. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions From 7f609f4b10fc853e7ef88b49f8e737bf3ada7261 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 11 Nov 2025 14:32:05 +0200 Subject: [PATCH 2/2] Update description wording --- .../Static-extensions/lexical_lookup_A01_t01.dart | 4 ++-- .../Static-extensions/lexical_lookup_A01_t02.dart | 4 ++-- .../Static-extensions/lexical_lookup_A01_t03.dart | 4 ++-- .../Static-extensions/lexical_lookup_A01_t04.dart | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart index 6b2b20ee32..da110f612d 100644 --- a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t01.dart @@ -9,8 +9,8 @@ /// extension. /// /// @description Checks that a static member of an extension can be invoked if -/// an expression in an extension declaration resolves to an invocation of a -/// static member of the enclosing extension. Test a static variable invocation. +/// an expression in the extension declaration resolves to an invocation of it. +/// Test a static variable invocation. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart index 9661f88f9f..109a70773c 100644 --- a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t02.dart @@ -9,8 +9,8 @@ /// extension. /// /// @description Checks that a static member of an extension can be invoked if -/// an expression in an extension declaration resolves to an invocation of a -/// static member of the enclosing extension. Test a static getter invocation. +/// an expression in the extension declaration resolves to an invocation of it. +/// Test a static getter invocation. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart index 89c9c6f5da..a0d4be72ea 100644 --- a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t03.dart @@ -9,8 +9,8 @@ /// extension. /// /// @description Checks that a static member of an extension can be invoked if -/// an expression in an extension declaration resolves to an invocation of a -/// static member of the enclosing extension. Test a static method invocation. +/// an expression in the extension declaration resolves to an invocation of it. +/// Test a static method invocation. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions diff --git a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart index 8cae18175a..1e1d8308fc 100644 --- a/LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart +++ b/LanguageFeatures/Static-extensions/lexical_lookup_A01_t04.dart @@ -9,8 +9,8 @@ /// extension. /// /// @description Checks that a static member of an extension can be invoked if -/// an expression in an extension declaration resolves to an invocation of a -/// static member of the enclosing extension. Test a static setter invocation. +/// an expression in the extension declaration resolves to an invocation of it. +/// Test a static setter invocation. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=static-extensions