hazzik / DelegateDecompiler

A library which is able to decompile a delegate or a method body to its lambda representation
MIT License
528 stars 62 forks source link

Perplexing decompiled expression #135

Open bradmarder opened 5 years ago

bradmarder commented 5 years ago

I don't quite understand what is going on with the following decompiled expression.

this => IIF(this.HasBar, this.Posts.Any(x => True), (this.HasBaz AndAlso this.Posts.Any((x => True ?? x => True))))

More specifically, this part is perplexing. this.Posts.Any((x => True ?? x => True)) I'm assuming it should only be this.Posts.Any(x => True) My basis for this assumption is if you change the || to just |, then it works fine.

When using that expression in conjunction with EFCore/Remotion.LINQ, those libraries fail to parse the expression and throw an exception. I don't know where the actual problem lies. Any help would be appreciated.

Here is the code.

using System;
using System.Collections.Generic;
using System.Linq;
using DelegateDecompiler;

namespace DecompileBug
{
    class Program
    {
        static void Main(string[] args)
        {
            var hasFoo = typeof(Blog)
                .GetProperties()
                .Single(x => x.Name == nameof(Blog.HasFoo))
                .GetMethod
                .Decompile()
                .ToString();

            Console.WriteLine(hasFoo);
            Console.ReadLine();
        }
    }
    public class Post { }
    public class Blog
    {
        public bool HasBar { get; }
        public bool HasBaz { get; }

        public IEnumerable<Post> Posts { get; }

        [Computed]
        public bool HasFoo =>
            (HasBar || HasBaz)
            && Posts.Any(x => true);
    }
}