icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
20.7k stars 3.29k forks source link

Callsite out variable declarations are no longer typed in ILSpy 6.2p2 #2165

Open lbmaian opened 3 years ago

lbmaian commented 3 years ago

This a regression of sorts from the fix for #2140 where out variable declarations at callsites always decompile to out var rather than out <type>. This behavior differs from ILSpy 6.1.

AFAIK, there is no decompiler option for toggling "var" vs the actual type.

Input code

Decompiler settings reset to default.

Source as entered in LINQPad 5:

void Main()
{
    Foo(out bool x);
    Console.WriteLine(x);
    Foo(out bool _);
}

void Foo(out bool x)
{
    x = true;
}

Assembly: query_rfjjvu.zip

Erroneous output

Actual decompiled Main:

    Foo(out var x);
    Console.WriteLine(x);
    Foo(out var _);

Expected decompiled Main (as decompiled by ILSpy 6.1):

    Foo(out bool x);
    Console.WriteLine(x);
    Foo(out bool _);

Details

siegfriedpammer commented 3 years ago

so you are asking for an option to always use T instead of var?

lbmaian commented 3 years ago

Well, I'd prefer an option to use var instead of actual type wherever var can be used - not something specific to out var.

But in the absence of that, for consistency, I think var (including out var) should only be used for anonymous types like before.