ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

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

Open lbmaian opened this issue 5 years ago • 2 comments

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

  • Product in use: ILSpy
  • Version in use: 6.2.0.6118-preview2

lbmaian avatar Sep 19 '20 20:09 lbmaian

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

siegfriedpammer avatar Sep 19 '20 20:09 siegfriedpammer

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.

lbmaian avatar Sep 19 '20 20:09 lbmaian