-
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
Implement val escape for switch expressions #45242
Conversation
@dotnet/roslyn-compiler May I please have a couple reviews of this tiny bug fix? |
_ => default, | ||
}; | ||
|
||
return span; // 3 |
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.
span; // 3 [](start = 15, length = 10)
Why is this error in GetSpan3
reported on the return
while the error in GetSpan2
is reported within the switch
expression? I'm curious in case the difference points to an issue. #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.
There is no problem in GetSpan3
until the return
. The switch expression simply computes a Span
value that cannot be returned, and is used to declare the local span
which therefore cannot be returned. It is only when you attempt to return that value that there is an issue.
In reply to: 441674063 [](ancestors = 441674063)
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.
There is no problem in
GetSpan3
until thereturn
.
Isn't that true for GetSpan2
as well? It looks like the only difference between the two cases is whether the local is assigned in the declaration. #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 don't track whether a variable can be returned based on the flow of data (like we do with nullable) but based on the "returnable" property of the local computed at the declaration point.
In GetSpan2
the local is returnable so we cannot even assign the switch expression to it.
In GetSpan3
the local is not returnable (because its initializing expression isn't returnable) so the assignment of the switch expression to it isn't a problem.
See https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/span-safety.md#locals for the precise rules.
In reply to: 441738383 [](ancestors = 441738383)
Fixes #44588