Skip to content

Equality comparison with nullables throws at delegate-invoke #67

@Banjobeni

Description

@Banjobeni

The following expressions compile successfully, but exceptions are thrown during execution of the resulting delegates. The first is the one i'd actually like to use, and the second is a failed attempt to circumvent the first.

        class Foo {
            public int? Prop { get; set; }
        }

        static void Main(string[] args) {
            int int32Comparand = 1;
            Expression<Func<Foo, bool>> a = foo => foo.Prop == int32Comparand;

            var ac = a.CompileFast();
            var ar1 = ac(new Foo { Prop = null }); // throws NullReferenceException
            var ar2 = ac(new Foo { Prop = 1 }); // throws NullReferenceException

            Expression<Func<Foo, bool>> b = foo => Nullable.Equals(foo.Prop, null);

            var bc = b.CompileFast();
            var br1 = bc(new Foo { Prop = null }); // throws AccessViolationException
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions