Commit 368277d
[private named parameters] Implement in analyzer
I considered a few different approaches for how to model a formal parameter having a public and private name. Here's a simple example:
```dart
class C {
int? _f;
C({this._f});
}
main() {
C(f: 1);
}
```
Here, it seems like the right approach is to give the formal parameter the public name since that's what you pass for the parameter. Then have resolution understand that the parameter can still map to a private instance variable.
But then consider:
```dart
class C {
int? _f;
int? x;
C({this._f}) : x = _f;
}
```
The formal parameter for _f can also be accessed inside the initializer list and here it must have the private name.
So, really, the name of the formal parameter *is* the private name. It's what the user wrote. It's the name that matches the instance field. It's the name that can be used to access the formal parameter in the initializer list.
The *only* places the public name come into play are:
1. The name you use to pass an argument to that parameter in a named expression.
2. The generated Dartdoc for that constructor.
Given that, I though a simple solution might be to give FormalParameterElement another property for "argument name". In places where we are binding an argument to the parameter, we use that to figure out which parameter is being referred to. Later when I work on Dartdoc support, I'll use that when generating the constructor signature.
Everything else just keeps using the name.
Thoughts?
Change-Id: Id6ccf8d850480f141dc0dc6e26f7b185b60f6c3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459663
Reviewed-by: Konstantin Shcheglov <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Bob Nystrom <[email protected]>
Auto-Submit: Bob Nystrom <[email protected]>1 parent 3125f46 commit 368277d
File tree
17 files changed
+538
-6
lines changed- pkg/analyzer
- lib
- dart/element
- src
- dart
- analysis
- element
- resolver
- generated
- summary2
- test/src
- dart/resolution
- summary
- elements
17 files changed
+538
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3642 | 3642 | | |
3643 | 3643 | | |
3644 | 3644 | | |
| 3645 | + | |
3645 | 3646 | | |
3646 | 3647 | | |
3647 | 3648 | | |
3648 | 3649 | | |
3649 | 3650 | | |
| 3651 | + | |
3650 | 3652 | | |
3651 | 3653 | | |
3652 | 3654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1253 | 1253 | | |
1254 | 1254 | | |
1255 | 1255 | | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
1256 | 1274 | | |
1257 | 1275 | | |
1258 | 1276 | | |
| |||
1268 | 1286 | | |
1269 | 1287 | | |
1270 | 1288 | | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
1271 | 1296 | | |
1272 | 1297 | | |
1273 | 1298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
2856 | 2857 | | |
2857 | 2858 | | |
2858 | 2859 | | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
2859 | 2863 | | |
2860 | 2864 | | |
2861 | 2865 | | |
| |||
2865 | 2869 | | |
2866 | 2870 | | |
2867 | 2871 | | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
2868 | 2876 | | |
2869 | 2877 | | |
2870 | 2878 | | |
2871 | 2879 | | |
2872 | 2880 | | |
2873 | 2881 | | |
2874 | 2882 | | |
| 2883 | + | |
2875 | 2884 | | |
2876 | 2885 | | |
2877 | 2886 | | |
| |||
3110 | 3119 | | |
3111 | 3120 | | |
3112 | 3121 | | |
3113 | | - | |
3114 | | - | |
3115 | | - | |
| 3122 | + | |
3116 | 3123 | | |
3117 | 3124 | | |
3118 | 3125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
558 | 561 | | |
559 | 562 | | |
560 | 563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
27 | 35 | | |
28 | 36 | | |
29 | 37 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
| 476 | + | |
476 | 477 | | |
477 | 478 | | |
478 | 479 | | |
| |||
667 | 668 | | |
668 | 669 | | |
669 | 670 | | |
| 671 | + | |
670 | 672 | | |
671 | 673 | | |
672 | 674 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6032 | 6032 | | |
6033 | 6033 | | |
6034 | 6034 | | |
| 6035 | + | |
| 6036 | + | |
| 6037 | + | |
| 6038 | + | |
| 6039 | + | |
| 6040 | + | |
6035 | 6041 | | |
6036 | 6042 | | |
6037 | 6043 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
743 | 743 | | |
744 | 744 | | |
745 | 745 | | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
746 | 749 | | |
747 | 750 | | |
748 | 751 | | |
| |||
1051 | 1054 | | |
1052 | 1055 | | |
1053 | 1056 | | |
| 1057 | + | |
| 1058 | + | |
1054 | 1059 | | |
1055 | 1060 | | |
1056 | 1061 | | |
| |||
1064 | 1069 | | |
1065 | 1070 | | |
1066 | 1071 | | |
| 1072 | + | |
1067 | 1073 | | |
1068 | 1074 | | |
1069 | 1075 | | |
1070 | 1076 | | |
| 1077 | + | |
1071 | 1078 | | |
1072 | 1079 | | |
1073 | 1080 | | |
| |||
1780 | 1787 | | |
1781 | 1788 | | |
1782 | 1789 | | |
| 1790 | + | |
| 1791 | + | |
1783 | 1792 | | |
1784 | 1793 | | |
1785 | 1794 | | |
| |||
1793 | 1802 | | |
1794 | 1803 | | |
1795 | 1804 | | |
| 1805 | + | |
1796 | 1806 | | |
1797 | 1807 | | |
1798 | 1808 | | |
1799 | 1809 | | |
| 1810 | + | |
1800 | 1811 | | |
1801 | 1812 | | |
1802 | 1813 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
626 | 626 | | |
627 | 627 | | |
628 | 628 | | |
| 629 | + | |
| 630 | + | |
629 | 631 | | |
630 | 632 | | |
631 | 633 | | |
632 | 634 | | |
633 | 635 | | |
634 | 636 | | |
635 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
636 | 643 | | |
637 | 644 | | |
638 | 645 | | |
| |||
1019 | 1026 | | |
1020 | 1027 | | |
1021 | 1028 | | |
| 1029 | + | |
1022 | 1030 | | |
1023 | 1031 | | |
1024 | 1032 | | |
| |||
1030 | 1038 | | |
1031 | 1039 | | |
1032 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1033 | 1044 | | |
1034 | 1045 | | |
1035 | 1046 | | |
| |||
1041 | 1052 | | |
1042 | 1053 | | |
1043 | 1054 | | |
| 1055 | + | |
1044 | 1056 | | |
1045 | 1057 | | |
1046 | 1058 | | |
| |||
1052 | 1064 | | |
1053 | 1065 | | |
1054 | 1066 | | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
1055 | 1071 | | |
1056 | 1072 | | |
1057 | 1073 | | |
| |||
0 commit comments