Skip to content

Decompilation of anonymous-type returning lambda with early return emits <>f__AnonymousTypeN #3751

@jakobhellermann

Description

@jakobhellermann

Input code

A return null; statement inside a lambda whose return type is inferred to an anonymous type. Minimal repro:

using System;

class Repro
{
    static bool Cond;

    static T Infer<T>(Func<T> factory) => factory();   // T is inferred to the anonymous type

    public object Trigger()
    {
        return Infer(() =>
        {
            if (Cond)
            {
                Console.WriteLine();
                return null;
            }
            return new { Value = 1 };
        });
    }
}

Erroneous output

public object Trigger()
{
    return Infer(delegate
    {
        if (Cond)
        {
            Console.WriteLine(); // prevent ternary
            return (<>f__AnonymousType0<int>)null;
        }
        return new { Value = 1 };
    });
}

return (<>f__AnonymousType0<int>)null; does not recompile — <>f__AnonymousType0 is not a referenceable identifier:

error CS1525: Invalid expression term '<'

Details

  • Product in use: ICSharpCode.Decompiler (via ilspycmd)
  • Version in use: 10.1.0.8388, built from master (ddbb24f24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDecompilerThe decompiler engine itself

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions