-
Notifications
You must be signed in to change notification settings - Fork 29
#3329. Add private named parameters tests. #3362
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
52 changes: 52 additions & 0 deletions
52
LanguageFeatures/Private-named-parameters/static_semantics_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,52 @@ | ||
| // 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 there is no error then: | ||
| /// - The parameter name of the parameter in the constructor is the public name | ||
| /// `n`. This means that the parameter has a public name in the constructor's | ||
| /// function signature, and arguments for this parameter are given using the | ||
| /// public name. All uses of the constructor, outside of its own code, see | ||
| /// only the public name. | ||
| /// | ||
| /// @description Check that the name of the parameter in the constructor | ||
| /// signature is a corresponding public name `n`. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C { | ||
| String? _p; | ||
|
|
||
| C({this._p}); | ||
| C.named({required this._p}); | ||
| } | ||
|
|
||
| extension type ET._(String? _p) { | ||
| ET({this._p}); | ||
| ET.named({required this._p}); | ||
| } | ||
|
|
||
| enum E { | ||
| e0(p: "0"), e1.named(p: "1"); | ||
|
|
||
| final String? _p; | ||
|
|
||
| const E({this._p}); | ||
| const E.named({required this._p}); | ||
| } | ||
|
|
||
| main() { | ||
| C.new.expectStaticType<Exactly<C Function({String? p})>>(); | ||
| C.named.expectStaticType<Exactly<C Function({required String? p})>>(); | ||
| ET.new.expectStaticType<Exactly<ET Function({String? p})>>(); | ||
| ET.named.expectStaticType<Exactly<ET Function({required String? p})>>(); | ||
| Expect.equals("0", E.e0._p); | ||
| Expect.equals("1", E.e1._p); | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
LanguageFeatures/Private-named-parameters/static_semantics_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,55 @@ | ||
| // 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 there is no error then: | ||
| /// - The parameter name of the parameter in the constructor is the public name | ||
| /// `n`. This means that the parameter has a public name in the constructor's | ||
| /// function signature, and arguments for this parameter are given using the | ||
| /// public name. All uses of the constructor, outside of its own code, see | ||
| /// only the public name. | ||
| /// | ||
| /// @description Check that the name of the parameter in the constructor | ||
| /// signature is a corresponding public name `n`. Test declaring constructors. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
| import '../../Utils/static_type_helper.dart'; | ||
|
|
||
| class C1({var String?_p}); | ||
eernstg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class C2 { | ||
| this({required final String _p}); | ||
| } | ||
|
|
||
| extension type ET1 { | ||
| this({final String? _p}); | ||
| } | ||
|
|
||
| extension type ET2 { | ||
| this({required final String _p}); | ||
| } | ||
|
|
||
| enum E1({final String? _p}) { | ||
| e0(p: "E1"); | ||
| } | ||
|
|
||
| enum E2 { | ||
| e0(p: "E2"); | ||
|
|
||
| const this({required final String _p}); | ||
| } | ||
|
|
||
| main() { | ||
| C1.new.expectStaticType<Exactly<C1 Function({String? p})>>(); | ||
| C2.new.expectStaticType<Exactly<C2 Function({required String p})>>(); | ||
| ET1.new.expectStaticType<Exactly<ET1 Function({String? p})>>(); | ||
| ET2.new.expectStaticType<Exactly<ET2 Function({required String p})>>(); | ||
| Expect.equals("E1", E1.e0._p); | ||
| Expect.equals("E2", E2.e1._p); | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
LanguageFeatures/Private-named-parameters/static_semantics_A03_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,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 there is no error then: | ||
| /// - The parameter name of the parameter in the constructor is the public name | ||
| /// `n`. This means that the parameter has a public name in the constructor's | ||
| /// function signature, and arguments for this parameter are given using the | ||
| /// public name. All uses of the constructor, outside of its own code, see | ||
| /// only the public name. | ||
| /// | ||
| /// @description Check that it is a compile-time error to use a private name `p` | ||
| /// as the name of the parameter in the constructor signature. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| class C { | ||
| String? _p; | ||
|
|
||
| C({this._p}); | ||
| C.named({required this._p}); | ||
| } | ||
|
|
||
| extension type ET._(String? _p) { | ||
| ET({this._p}); | ||
| ET.named({required this._p}); | ||
| } | ||
|
|
||
| enum E { | ||
| e0(_p: "0"), | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| e1.named(_p: "1"); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| final String? _p; | ||
|
|
||
| const E({this._p}); | ||
| const E.named({required this._p}); | ||
| } | ||
|
|
||
| main() { | ||
| C(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| C.named(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET.named(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } |
72 changes: 72 additions & 0 deletions
72
LanguageFeatures/Private-named-parameters/static_semantics_A03_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,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 Given a named initializing formal or field parameter (for a | ||
| /// primary constructor) with private name `p` in constructor `C`: | ||
| /// ... | ||
| /// If there is no error then: | ||
| /// - The parameter name of the parameter in the constructor is the public name | ||
| /// `n`. This means that the parameter has a public name in the constructor's | ||
| /// function signature, and arguments for this parameter are given using the | ||
| /// public name. All uses of the constructor, outside of its own code, see | ||
| /// only the public name. | ||
| /// | ||
| /// @description Check that it is a compile-time error to use a private name `p` | ||
| /// as the name of the parameter in the constructor signature. Test declaring | ||
eernstg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// constructors. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors | ||
|
|
||
| class C1({var String?_p}); | ||
eernstg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class C2 { | ||
| this({required final String _p}); | ||
| } | ||
|
|
||
| extension type ET1 { | ||
| this({final String? _p}); | ||
| } | ||
|
|
||
| extension type ET2 { | ||
| this({required final String _p}); | ||
| } | ||
|
|
||
| enum E1({final String? _p}) { | ||
| e0(_p: "E1"); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
|
|
||
| enum E2 { | ||
| e0(_p: "E2"); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| const this({required final String _p}); | ||
| } | ||
|
|
||
| main() { | ||
| C1(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| C2(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET1(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
|
|
||
| ET2(_p: ""); | ||
| // ^^ | ||
| // [analyzer] unspecified | ||
| // [cfe] unspecified | ||
| } | ||
60 changes: 60 additions & 0 deletions
60
LanguageFeatures/Private-named-parameters/static_semantics_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,60 @@ | ||
| // 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 there is no error then: | ||
| /// ... | ||
| /// - The local variable introduced by the parameter, accessible only in the | ||
| /// initializer list, still has the private name `p`. | ||
| /// | ||
| /// @description Check that in the initializer list the name of the local | ||
| /// variable introduced by the parameter is the private name `p`. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
|
|
||
| class C { | ||
| String? _p1; | ||
| String? p2; | ||
|
|
||
| C({this._p1}) : p2 = _p1; | ||
| C.named({required this._p1}) : p2 = _p1; | ||
| } | ||
|
|
||
| String log = ""; | ||
|
|
||
| extension type ET._(String? _p) { | ||
| ET({this._p}) : assert(() {log = _p; return true;}()); | ||
| ET.named({required this._p}) : assert(() {log = _p; return true;}()); | ||
| } | ||
|
|
||
| enum E { | ||
| e0(p: "0"), e1.named(p: "1"); | ||
|
|
||
| final String? _p1; | ||
| final String? p2; | ||
|
|
||
| const E({this._p1}) : p2 = _p1; | ||
| const E.named({required this._p1}) : p2 = _p1; | ||
| } | ||
|
|
||
| main() { | ||
| Expect.equals("one", C(p1: "one").p2); | ||
| Expect.equals("two", C.named(p1: "two").p2); | ||
| ET(p: "one"); | ||
| if (log.isNotEmpty) { | ||
| Expect.equals("one", log); | ||
| log = ""; | ||
| } | ||
| ET.named(p: "two"); | ||
| if (log.isNotEmpty) { | ||
| Expect.equals("two", log); | ||
| } | ||
| Expect.equals("0", E.e0.p2); | ||
| Expect.equals("1", E.e1.p2); | ||
| } |
70 changes: 70 additions & 0 deletions
70
LanguageFeatures/Private-named-parameters/static_semantics_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,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 Given a named initializing formal or field parameter (for a | ||
| /// primary constructor) with private name `p` in constructor `C`: | ||
| /// ... | ||
| /// If there is no error then: | ||
| /// ... | ||
| /// - The local variable introduced by the parameter, accessible only in the | ||
| /// initializer list, still has the private name `p`. | ||
| /// | ||
| /// @description Check that in the initializer list the name of the local | ||
| /// variable introduced by the parameter is the private name `p`. Test declaring | ||
| /// constructors. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors | ||
|
|
||
| import '../../Utils/expect.dart'; | ||
|
|
||
| class C1({var String? _p1}) { | ||
| String? p2; | ||
| this : p2 = _p1; | ||
| } | ||
|
|
||
| class C2 { | ||
| String p2; | ||
| this({required final String _p1}) : p2 = _p1; | ||
| } | ||
|
|
||
| String log = ""; | ||
|
|
||
| extension type ET1 { | ||
| this({final String? _p}) : assert(() {log = _p; return true;}()); | ||
| } | ||
|
|
||
| extension type ET2 { | ||
| this({required final String _p}) : assert(() {log = _p; return true;}()); | ||
| } | ||
|
|
||
| enum E1({final String? _p1}) { | ||
| e0(p1: "E1"); | ||
|
|
||
| final String? p2; | ||
| this : p2 = _p1; | ||
| } | ||
|
|
||
| enum E2 { | ||
| e0(p1: "E2"); | ||
|
|
||
| final String p2; | ||
| const this({final String? _p1}) : p2 = _p1; | ||
| } | ||
|
|
||
| main() { | ||
| Expect.equals("one", C1(p1: "one").p2); | ||
| Expect.equals("two", C2(p1: "two").p2); | ||
| ET1(p: "one"); | ||
| if (log.isNotEmpty) { | ||
| Expect.equals("one", log); | ||
| log = ""; | ||
| } | ||
| ET2(p: "two"); | ||
| if (log.isNotEmpty) { | ||
| Expect.equals("two", log); | ||
| } | ||
| Expect.equals("E1", E1.e0.p2); | ||
| Expect.equals("E2", E2.e0.p2); | ||
| } |
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.