-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add support for static local functions #869
Add support for static local functions #869
Conversation
Merge v7 work
1e9d2d3
to
9fe7f49
Compare
rebased on updated |
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.
I made a suggested change for the "enclosing scope" sections.
In the suggestion, I removed the sentence saying that async
doesn't apply if the enclosing method is async
. I don't think it's needed with the new wording.
@RexJaeschke Should we mark this one ready for review? |
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.
I do wonder whether we need a note about the purpose of making a local function static. At the moment we say that removing the modifier from valid code doesn't change the meaning - but we don't say why you'd want to keep it anyway.
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.
I have a few comments to address, along with Jon's nits.
After that, this one is ready to merge. I don't think any rules on static local functions are missing.
I'm not sure it's clear that a static local function can call another static local function (but not a non-static local function), and that includes a static local function defined in an enclosing local function. @jskeet wrote:
A note might be worth it as using the keyword |
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
Co-authored-by: Neal Gafter <neal@gafter.com>
This reverts commit 0467ef9.
Note 1:
In researching this V8 feature, I discovered that while V7 stated, “It is a compile-time error for a [non-static] local function to declare a parameter or local variable with the same name as one declared in the enclosing scope.”, based on the implementation’s behavior when compiling with LangVersion 8, that restriction was removed in V8 for non-static local functions, and also does not apply to static local functions either.
I note this here to make sure this was the intent, as it was not so stated in the MS proposal for this feature.
Note 2:
The spec for 13.6.4 contains a pointer to 9.4.4.33, “Rules for variables in local functions,” part of which talks about capturing variables, which, clearly, static local functions can’t do. As such, a knowledgeable reader of that referred-to reference might be expected to understand that it can’t apply to static local functions. As such, I did not say that explicitly in that section.
Reviewers might want to add an explicit note about that.
Associated WorkItem - 209387