You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The question is, basically: does moving the readonly from the struct S declaration to the public int M declaration result in a legal program? And if so, what's a reasonable way to adjust the check in SpillSequenceSpiller to make that work?
I agree the current behavior is as described. I don't remember us making this explicit decision though hence I'm a bit interested in the reasoning here. To be clear this isn't "safe" as compared to traditional struct as it's still subject to mutations that are observable across await boundaries. Consider:
This prints 2 then 1. Hence it's the readonly struct here is clearly not making the spilling any safer here than for a normal struct. At least for the cases I can think of. Hence I'm unsure why we have this behavior at all.
My instinct though is that whatever the reason the rule should be that spilling is allowed when the struct receiver has type of in. That though would likely mean we need to extend to extension methods as well.
Related to #32911 and maybe #22055
There is a specific case where implicitly spilling a receiver by value is allowed only if the receiver's type is a readonly struct.
The check can be found here: https://github.com/dotnet/roslyn/blob/d89223c/src/Compilers/CSharp/Portable/Lowering/SpillSequenceSpiller.cs#L788
The question is, basically: does moving the
readonly
from thestruct S
declaration to thepublic int M
declaration result in a legal program? And if so, what's a reasonable way to adjust the check in SpillSequenceSpiller to make that work?cc @jaredpar @VSadov
The text was updated successfully, but these errors were encountered: