-
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
"ref readonly" local functions should be treated as "ref readonly" #18419
Conversation
The code was ignoring "readonly" part for local functions, Fixes:dotnet#18357
CC: @OmarTawfik |
@dotnet/roslyn-compiler - please 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.
Can we also add another test for the negative case? (ref-ness mismatch between local/outer functions).
Is it another code path as well?
@@ -73,7 +73,7 @@ internal sealed class LocalFunctionSymbol : MethodSymbol | |||
} | |||
|
|||
_binder = binder; | |||
_refKind = (syntax.ReturnType.Kind() == SyntaxKind.RefType) ? RefKind.Ref : RefKind.None; | |||
_syntax.ReturnType.SkipRef(out _refKind); |
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.
Consider adding a helper to make this idiom clearer. "Skipping" the ref to get the RefKind is not very obvious. #Resolved
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.
Also consider removing this field entirely and just computing the RefKind based on syntax every time. I bet the time/memory trade off here is not useful. Same with SourceMemberMethodSymbol. #Resolved
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.
we do not keep the syntax. we keep the reference, so it is not as trivial. I think I can make ref kind lazy for local functions.
Not so sure about MemberMethod though - getting return type is complicated there because of overriding. I'll keep it eager for MemberMethod.
In reply to: 109756907 [](ancestors = 109756907)
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 agree with @OmarTawfik. I'd like to see a negative test case here as well.
@agocke - looks ok? |
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 meant that you could remove the refkind field and just have a property that computes the value every time. It seems trivial to calculate from the syntax and having an extra bool doesn't seem with it. But this is also fine and had the plus that all the calculation is in the same place. LGTM
LGTM |
The code was ignoring "readonly" part for local functions,
Fixes:#18357