Skip to content

Error decompiling generic extension in 0.35, was working before #298

@beno-pete

Description

@beno-pete

In following code decompiling Ext2() throws error while decompiling Ext1() works properly.
This only happens in recent 0.35 version, it works properly with previous version.
The only difference in extension methods is explicit type casting in Ext1() while Ext2() uses implicit casting because of generic constraint.

using DelegateDecompiler;
using System.Linq;

namespace ConsoleApp1;

static class Program
{
    static void Main()
    {
        var q = new Cls[0].AsQueryable();
        var a = DecompileExtensions.Decompile(q.Select(x => x.Ext1()));
        var b = DecompileExtensions.Decompile(q.Select(x => x.Ext2()));
    }

    [Computed]
    public static int Ext1<T>(this T value) where T : Intf => ((Intf)value).Value;

    [Computed]
    public static int Ext2<T>(this T value) where T : Intf => value.Value;

}

public interface Intf
{
    public int Value { get; }
}

public class Cls : Intf
{
    public int Value { get; set; }
}
System.NotSupportedException
  HResult=0x80131515
  Message=The IL opcode 'constrained.' is not supported by DelegateDecompiler. This opcode cannot be decompiled into an expression tree. Consider simplifying the method or using a different approach.
  Source=DelegateDecompiler
  StackTrace:
   at DelegateDecompiler.Processor.ProcessInstruction(ProcessorState state, Instruction instruction)
   ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions