-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
LocalFunctionSymbol.IsStatic always returns true #27719
Comments
We classify "methods" into instance methods, which are invoked off an enclosing instance, and static methods, which are not. It is under this classification that local functions are considered static methods. |
@gafter I see. Do you know where "static" is described in the spec? Our public API is useless here, it says "Gets a value indicating whether the symbol is static". @jcouv If we've defined static in this context to mean "does not have a receiver", this may actually be the correct behavior. I still think messing with the declaration modifiers was a bad idea though. |
@agocke The C# language spec won't say anything about this. It is an artifact of Roslyn modeling local functions as methods. Roslyn's engineers had to make up their own definition that somehow mediates that mushed-together model, and this is what we (you?) came up with. There is a proposal to give meaning to "static" on local functions (that do not capture anything), and if we do that we'll need to represent that concept somehow; the "static" modifier seems the best thing for that purpose. If and when we do that, we'd have to make regular local functions (that can capture stuff) not have the static modifier set. Should we preemptively make that change now? I don't know whether or not that is the best approach. |
I was referring to the meaning of static on members. I thought it may be useful to compare the description there with whatever we choose for local functions. The spec says per https://github.com/dotnet/csharplang/blob/master/spec/classes.md#static-and-instance-members
That statement conveniently allows for multiple interpretations. Either a local function could be always static because it doesn't operate on a specific instance, or it could be static only when it can refer to Looking at the full definition I think @jcouv's definition of a local function being static if it cannot access |
Local functions are not members, so we can justify whatever we want to do 😉 |
We should just clean this up as we actually implement |
I gave this a quick try - I made local functions non- static unless they were static local functions, and added another method My conclusion: the vast majority of calls to IMO this is error prone, and has little benefit. Instead, I would suggest that We then move |
@agocke Can this issue be closed now? If not, it probably can be moved to Compiler.Next milestone. |
Yup, this is can be closed out |
Current constructor always sets an implicit declaration modifier:
IsStatic
checks the declaration modifiers:From discussion with @agocke and @AlekseyTs,
IsStatic
should always returnfalse
. Some overload resolution logic may need to be adjusted (to have special handling for local functions).To save some typing, here's a test I had.
Relates to #27028
Note: in the implementation of static local functions, an internal property
IsStaticLocalFunction
was added. It should be removed when this issue is fixed.The text was updated successfully, but these errors were encountered: