-
Notifications
You must be signed in to change notification settings - Fork 28
#3329. Add more private named parameters tests #3375
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
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
59 changes: 59 additions & 0 deletions
59
LanguageFeatures/Private-named-parameters/static_semantics_A01_t04.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,59 @@ | ||
| // 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 Given a named initializing formal or field parameter (for a | ||
| /// primary constructor) with private name `p` in constructor `C`: | ||
| /// - If `p` has no corresponding public name `n`, then compile-time error. | ||
| /// | ||
| /// @description Check that it is a compile-time error if a named initializing | ||
| /// formal parameter has a private name that has no corresponding public name. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| class C { | ||
| String _; | ||
| C({this._ = ""}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| C._({required this._}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET._(String _) { | ||
| ET({this._ = ""}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET.named({required this._}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E { | ||
| e0; | ||
|
|
||
| final String _; | ||
| const E({this._ = ""}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| const E.named({required this._}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(C); | ||
| print(ET); | ||
| print(E); | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
LanguageFeatures/Private-named-parameters/static_semantics_A01_t05.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,84 @@ | ||
| // 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 Given a named initializing formal or field parameter (for a | ||
| /// primary constructor) with private name `p` in constructor `C`: | ||
| /// - If `p` has no corresponding public name `n`, then compile-time error. | ||
| /// | ||
| /// @description Check that it is a compile-time error if a declaring named | ||
| /// formal parameter of a declaring constructor has a private name with no | ||
| /// corresponding public name. | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors | ||
|
|
||
| class C1({var String __}) { | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| class C2({required final String _}) { | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| class C3 { | ||
| this({required final String _}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| class C4 { | ||
| this({var String __ = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET1 { | ||
| this({final String __ = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET2 { | ||
| this({final String _ = ""}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E1({required final String __}) { | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| e0(_: ""); | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E2 { | ||
| e0; | ||
|
|
||
| const this({final String _ = ""}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(C1); | ||
| print(C2); | ||
| print(C3); | ||
| print(C4); | ||
| print(ET1); | ||
| print(ET2); | ||
| print(E1); | ||
| print(E2); | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
LanguageFeatures/Private-named-parameters/static_semantics_A02_t03.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,65 @@ | ||
| // 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 Given a named initializing formal or field parameter (for a | ||
| /// primary constructor) with private name `p` in constructor `C`: | ||
| /// - If `p` has no corresponding public name `n`, then compile-time error. You | ||
| /// can't use a private name for a named parameter unless there is a valid | ||
| /// public name that could be used at the call site. | ||
| /// - If any other parameter in `C` has declared name `p` or `n`, then | ||
| /// compile-time error. | ||
| /// | ||
| /// @description Check that it is a compile-time error if any other parameter in | ||
| /// `C` has declared name `p` or `n`. Test initializing formals. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| class C { | ||
| String _p; | ||
| String p; | ||
| C(String p, {this._p = ""}) : p = p; | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| C._(this.p, {required this._p}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET._(String _p) { | ||
| ET(int p, {this._p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET.named(int p, {required this._p}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E { | ||
| e0(1); | ||
|
|
||
| final String _p; | ||
| final int? p; | ||
| const E(int? p, {this._p = ""}) : p = p; | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| const E.named(this.p, {required this._p}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(C); | ||
| print(ET); | ||
| print(E); | ||
| } |
69 changes: 69 additions & 0 deletions
69
LanguageFeatures/Private-named-parameters/static_semantics_A02_t04.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,69 @@ | ||
| // 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 Given a named initializing formal or field parameter (for a | ||
| /// primary constructor) with private name `p` in constructor `C`: | ||
| /// - If `p` has no corresponding public name `n`, then compile-time error. You | ||
| /// can't use a private name for a named parameter unless there is a valid | ||
| /// public name that could be used at the call site. | ||
| /// - If any other parameter in `C` has declared name `p` or `n`, then | ||
| /// compile-time error. | ||
| /// | ||
| /// @description Check that it is a compile-time error if any other parameter in | ||
| /// `C` has declared name `p` or `n`. Test declaring parameters. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors | ||
|
|
||
| class C1(int p, {var String _p = ""}) { | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| class C2 { | ||
| this(int p, {final String _p = "", }); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET1 { | ||
| this(int p, {final String _p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET2 { | ||
| this(int p, {final String _p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E1(int p, {final String _p = ""}) { | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| e0(1); | ||
| } | ||
|
|
||
| enum E2 { | ||
| e0(2); | ||
|
|
||
| const this(int? p, {final String _p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(C1); | ||
| print(C2); | ||
| print(ET1); | ||
| print(ET2); | ||
| print(E1); | ||
| print(E2); | ||
| } |
58 changes: 58 additions & 0 deletions
58
LanguageFeatures/Private-named-parameters/super_parameters_A01_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 A super parameter generates an implicit argument that forwards to | ||
| /// a superclass constructor. The super constructor's argument name is always | ||
| /// public, even if the corresponding constructor parameter uses this feature | ||
| /// and has a private name. Thus, super parameters continue to always use public | ||
| /// names. | ||
| /// | ||
| /// @description Check that private super parameter can be invoked using its | ||
| /// public name. | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
|
|
||
| class A1 { | ||
| String _p; | ||
| A1({this._p = ""}); | ||
| } | ||
|
|
||
| class A2 { | ||
| String _p; | ||
| A2({required this._p}); | ||
| } | ||
|
|
||
| class C1 extends A1 { | ||
| C1({super.p}); | ||
| C1.named({super.p}); | ||
| } | ||
|
|
||
| class C2 extends A2 { | ||
| C2({required super.p}); | ||
| C2.named({required super.p}); | ||
| } | ||
|
|
||
| class C3 extends A1 { | ||
| C3(String p) : super(p: p); | ||
| C3.named(String p) : super(p: p); | ||
| } | ||
|
|
||
| class C4 extends A2 { | ||
| C4(String p) : super(p: p); | ||
| C4.named(String p) : super(p: p); | ||
| } | ||
|
|
||
| main() { | ||
| Expect.equals("a", C1(p: "a")._p); | ||
| Expect.equals("b", C1.named(p: "b")._p); | ||
| Expect.equals("c", C2(p: "c")._p); | ||
| Expect.equals("d", C2.named(p: "d")._p); | ||
| Expect.equals("e", C3("e")._p); | ||
| Expect.equals("f", C3.named("f")._p); | ||
| Expect.equals("g", C4("g")._p); | ||
| Expect.equals("h", C4.named("h")._p); | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
LanguageFeatures/Private-named-parameters/super_parameters_A01_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,38 @@ | ||
| // 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 A super parameter generates an implicit argument that forwards to | ||
| /// a superclass constructor. The super constructor's argument name is always | ||
| /// public, even if the corresponding constructor parameter uses this feature | ||
| /// and has a private name. Thus, super parameters continue to always use public | ||
| /// names. | ||
| /// | ||
| /// @description Check that private super parameter can be invoked using its | ||
| /// public name. Test declaring constructors. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
|
|
||
| class A1 { | ||
| String _p; | ||
| A1({this._p = ""}); | ||
| } | ||
|
|
||
| class A2 { | ||
| String _p; | ||
| A2({required this._p}); | ||
| } | ||
|
|
||
| class C1({super.p}) extends A1; | ||
|
|
||
| class C2 extends A2 { | ||
| this({required super.p}); | ||
| } | ||
|
|
||
| main() { | ||
| Expect.equals("a", C1(p: "a")._p); | ||
| Expect.equals("b", C2(p: "b")._p); | ||
| } |
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.