-
Notifications
You must be signed in to change notification settings - Fork 228
Adjust wording in the 'Private named parameters' proposal #4561
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
Conversation
|
Thanks! |
With that parenthetical, are you saying that a declaring field parameter is in scope in the constructor body? That's not what I'd expect: class C({this._s}) {
String? _s;
void Function()? _capture;
init {
_capture = () {
print(_s);
}
}
}
main() {
var c = C(s: 'before');
c._s = 'after';
c._capture!.call();
}I expect this program would print "after", meaning that class C {
String? s;
void Function()? capture;
C({this.s}) {
capture = () {
print(s);
};
}
}
main() {
var c = C(s: 'before');
c.s = 'after';
c.capture!.call();
}The primary constructors proposal says:
My emphasis added. So I think the proposal is in line with what I'm saying. Am I just misreading your parenthetical? |
Oops, that was a typo. I just corrected the phrase to 'if not declaring or initializing'.
Right, the declaring parameter is not in scope in the body, it is treated in the same way as an initializing formal.
Agreed! |
Zhigan650
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec_adjust_intro_nov25
|
@copilot |
|
Pull request successfully merged and closed |
The beginning of the 'private named parameters' proposal may currently be interpreted to mean that a declaring or initializing formal with a name of the form
_idis treated as if it had had the nameidfor all purposes other than the naming of the implicitly induced instance variable. It is in fact still accessed as_idin the initializer list and (if not declaring or initializing) in the constructor body. This PR adds a few words to make it explicit that the corresponding public name is only used at call sites. It could be spelled out even more. However, that's probably not necessary because the details are given later in the proposal, and we just want to get the reader on track to the overall properties of the proposal here.