-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix type parameter scoping for local functions #59968
Conversation
@RikkiGibson #Resolved (hopefully 😄 ) |
@@ -358,7 +358,7 @@ private static Binder GetEnclosingBinderInternalWithinRoot(SyntaxNode node, int | |||
LocalFunctionSymbol function = GetDeclaredLocalFunction(binder, ownerOfTypeParametersInScope.Identifier); | |||
if ((object)function != null) | |||
{ | |||
binder = function.SignatureBinder; | |||
binder = function.ParameterBinder; |
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.
SignatureBinder
is used for attribute binding, hence, it doesn't have type parameters in scope. This code path used by LookupPosition
wants to have type parameters in scope, so I switched to using ParameterBinder
here.
@jcouv I was hoping this would be fixed as part of 'nameof(param)'--and that we would allow it, i.e. 'nameof(T)' within an attribute. Is that the plan? |
@RikkiGibson Whether to allow |
@jcouv @RikkiGibson Is there a conclusion yet on whether this would be allowed or not? |
The internal thread concluded that both type parameter names and parameter names should be available in 'nameof' on attributes. Therefore, I think we shouldn't take the change here, and should just correct the behavior as part of the language feature implementation--possibly adding a LangVersion diagnostic for referencing type parameter names in local functions pre-C# 11, for example. |
That would be for regular methods too? It's currently not allowed. |
Yes, that's another place we would add a LangVersion diagnostic. |
Great. I'll close this PR and see if I can get another PR for the lang version checks and regular methods. |
@Youssef1313 I would not close this PR. What Rikki meant is that in C# 11, we'll end up allowing this as part of |
Let me chat with Rikki. I see his point. |
From chat with @RikkiGibson we still think this PR is useful to establish correct C# 10 baseline. Let's re-open please |
I'll just integrate this close PR into my WIP PR for C# 11: #40525. That'll reduce need to coordinate around this issue. Thanks |
Fixes #59775
@RikkiGibson Tagging you since you were assigned the issue.
Previously we were using
WithMethodTypeParametersBinder
for binding, including local function attributes. Now I'm using_withTypeParamsBinder
when needed, ie, for everything except attributes (which usesSignatureBinder
).Does this look correct?