Skip to content

Optional parameters with implicit default values #3469

@ds5678

Description

@ds5678

Input code

.assembly extern System.Runtime
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 4:0:0:0
}

.class public auto ansi abstract sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3469
    extends [System.Runtime]System.Object
{
    // Methods
    .method public hidebysig static 
        void M (
            [opt] int32 i,
            [opt] valuetype [System.Runtime]System.DateTime d
        ) cil managed 
    {
        .param [1] = int32(0)
        // Roslyn inserts, but Mono doesn't:
        // .param [2] = nullref
        // Method begins at RVA 0x2050
        // Code size 1 (0x1)
        .maxstack 8

        IL_0000: ret
    } // end of method Issue3469::M

} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue3469

Erroneous output

using System;
using System.Runtime.InteropServices;
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
	public static class Issue3469
	{
		public static void M(int i = 0, [Optional] DateTime d)
		{
		}
 	}
}
CS1737: Optional parameter cannot precede required parameters

Expected output

using System;
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
	public static class Issue3469
	{
		public static void M(int i = 0, DateTime d = default(DateTime))
		{
		}
 	}
}

Details

  • Product in use: IL pretty unit test
  • Version in use: latest commit (aff9649)
  • Any other relevant information to the issue, or your interest in contributing a fix.
    • I am always willing to contribute fixes for my issues.
    • This assembly was compiled with the Unity Mono compiler.
    • If this is a step too far, I can automatically preprocess the assembly with AsmResolver before using ILSpy. I already do this in other situations, like removing public keys from InternalsVisibleToAttribute.

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