-
Notifications
You must be signed in to change notification settings - Fork 29
#3330. Add static extensions tests. Part 2. #3382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+532
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
LanguageFeatures/Static-extensions/static_member_A03_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
70
LanguageFeatures/Static-extensions/static_member_A03_t02.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
72
LanguageFeatures/Static-extensions/static_member_A04_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
72
LanguageFeatures/Static-extensions/static_member_A04_t02.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
58
LanguageFeatures/Static-extensions/static_member_A05_t01.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.