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
Strstr=default(Str);try{}finally{// this is wrong((IDisposable)str).Dispose();// structs do not box in using pattern// see corresponding blog post from Eric Lippert// https://stackoverflow.com/a/2413844/5647513}
Unfortunately there's no good way to represent a constrained.call in C#.
Imagine the Str.Dispose method was an explicit interface implementation -- the using statement would still be able to call it without boxing, but how would you do the same without a using statement?
I think since user intentionally opt-ins (using is C# 1 feature -- always on by default) output should prefer correct semantics vs compile-ability. At least it's possible to drop cast for non explicit implementations and add a comment on explicit.
OwnageIsMagic
changed the title
struct in using binds by pattern in Roslyn
struct in using do not box
Sep 29, 2023
Input code
Erroneous output
Details
Sharplab uses v7
https://sharplab.io/#v2:CYLg1APgAgTAjAWAFDKgBgAQAoB2BTAdwwGUAXAJywEoqMBuVTXQjAJTwDMzKb7Ht8RAMIAbAM7VaDFEjEUArgGNSJChhAYAkgBEAlmIAOAezEBDAEYi8yAN7IMDjFADMTgCwY9hk3moYbAL7IQTLknBhy5Eoq7FwUtvaOLu6e+sZivrSBwcioMBiiYupaXukWVglIjk6uUB6lPn7ZSAFAA=
Also tested in ILSpy version 8.1.1.7464.
The text was updated successfully, but these errors were encountered: