Skip to content

Perplexing decompiled expression #135

@bradmarder

Description

@bradmarder

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);
    }
}

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