-
Notifications
You must be signed in to change notification settings - Fork 28
#3329. Add tests for "corresponding public name" #3361
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 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3acc75
#3329. Add tests for "corresponding public name"
sgrekhov 8f0a546
Implement review recommendations
sgrekhov 357119a
Fix syntax errors
sgrekhov e6dd5e2
Make static_semantics_A01_t01.dart stronger
sgrekhov 74f69c8
Add missing expected errors
sgrekhov 65534c0
Implement review recommendations
sgrekhov 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_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,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 _p; | ||
| C({this.__p = ""}); | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| C._({required this.__p}); | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET._(String _p) { | ||
eernstg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ET({this.__p = ""}); | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET.named({required this.__p}); | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E { | ||
| e0; | ||
|
|
||
| final String _p; | ||
eernstg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const E({this.__p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| const E.named({required this.__p}); | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(C); | ||
| print(ET); | ||
| print(E); | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
LanguageFeatures/Private-named-parameters/static_semantics_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,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 _1; | ||
| C({this._1 = ""}); | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| C._({required this._1}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET._(String _1) { | ||
| ET({this._1 = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET.named({required this._1}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E { | ||
| e0; | ||
|
|
||
| final String _1; | ||
| const E({this._1 = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| const E.named({required this._1}); | ||
| // ^^ | ||
| // [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_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,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 named formal | ||
| /// parameter of a declaring constructor has a private name with no | ||
| /// corresponding public name. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors | ||
|
|
||
| class C1({var String __p}) { | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| class C2({required final String _1}) { | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| class C3 { | ||
| this({required final String __p}); | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| class C4 { | ||
| this({var String _1 = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET1 { | ||
| this({final String __p = ""}); | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET2 { | ||
| this({final String _1 = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E1({required final String __p}) { | ||
| // ^^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| e0(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E2 { | ||
| e0; | ||
|
|
||
| const this({final String _1 = ""}); | ||
| // ^^ | ||
| // [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_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,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`. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| class C { | ||
| String _p; | ||
| String p; | ||
| C(int? _p, {this._p = "", }) : p = ""; | ||
eernstg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| C._({required this._p, this.p}); | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET._(String _p) { | ||
| ET(int _p, {this._p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET.named({required this._p, int? p}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E { | ||
| e0(1); | ||
|
|
||
| final String _p; | ||
| final int? p; | ||
| const E(int? _p, {this._p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| const E.named({required this._p, 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_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,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`. | ||
| /// @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({final String _p = "", int p = 0}); | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET1 { | ||
| this(int _p, {final String _p = ""}); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| extension type ET2 { | ||
| this({final String _p = "", int p = 0}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E1(int? _p, {final String _p = ""}) { | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| e0; | ||
| } | ||
|
|
||
| enum E2 { | ||
| e0; | ||
|
|
||
| const this({final String _p = "", final int? p}); | ||
| // ^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| main() { | ||
| print(C1); | ||
| print(C2); | ||
| print(ET1); | ||
| print(ET2); | ||
| print(E1); | ||
| print(E2); | ||
| } | ||
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.