-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Labels
Description
Input code
class UsingTest
{
struct TypeA : IDisposable
{
public void Dispose() { }
public static implicit operator TypeB(in TypeA a) => new();
}
struct TypeB { }
static void Test()
{
using (TypeA a = new())
Empty(a);
}
static void Empty(TypeB b) { }
}Erroneous output
internal class UsingTest
{
[StructLayout(LayoutKind.Sequential, Size = 1)]
private struct TypeA : IDisposable
{
public void Dispose()
{
}
public static implicit operator TypeB(in TypeA a)
{
return default(TypeB);
}
}
[StructLayout(LayoutKind.Sequential, Size = 1)]
private struct TypeB
{
}
private static void Test()
{
TypeA a = default(TypeA);
try
{
Empty(a);
}
finally
{
((IDisposable)a/*cast due to .constrained prefix*/).Dispose();
}
}
private static void Empty(TypeB b)
{
}
}This also happens when the types are classes.
Details
- Product in use: e.g. ILSpy 9.0 VS extension