Skip to content
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

Missing detection of using statement with implicit type cast #3385

Open
mmusu3 opened this issue Jan 30, 2025 · 0 comments
Open

Missing detection of using statement with implicit type cast #3385

mmusu3 opened this issue Jan 30, 2025 · 0 comments
Labels
Bug Decompiler The decompiler engine itself

Comments

@mmusu3
Copy link

mmusu3 commented Jan 30, 2025

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
@mmusu3 mmusu3 added Bug Decompiler The decompiler engine itself labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

1 participant