Skip to content

struct in using do not box #3089

@OwnageIsMagic

Description

@OwnageIsMagic

Input code

using System;

using (new Str()) ;

struct Str : IDisposable
{
    public void Dispose() {}
}

Erroneous output

Str str = 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
        }

Details

Sharplab uses v7
https://sharplab.io/#v2:CYLg1APgAgTAjAWAFDKgBgAQAoB2BTAdwwGUAXAJywEoqMBuVTXQjAJTwDMzKb7Ht8RAMIAbAM7VaDFEjEUArgGNSJChhAYAkgBEAlmIAOAezEBDAEYi8yAN7IMDjFADMTgCwY9hk3moYbAL7IQTLknBhy5Eoq7FwUtvaOLu6e+sZivrSBwcioMBiiYupaXukWVglIjk6uUB6lPn7ZSAFAA=

Also tested in ILSpy version 8.1.1.7464.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDecompilerThe decompiler engine itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions