Skip to content

Bad code-gen for comparison of nullable type to null #252

@kindermannhubert

Description

@kindermannhubert

Simplified example:

using static System.Linq.Expressions.Expression;

public static class Test
{
    public delegate void Handler(int? value);

    public static Handler Create()
    {
        var parameterExpr = Parameter(typeof(int?), "value");
        var toStringMethod = typeof(int?).GetMethod(nameof(object.ToString));
        var callExpr = Call(parameterExpr, toStringMethod);
        var callIfNotNull = IfThen(Not(Equal(parameterExpr, Constant(null, typeof(int?)))), callExpr);
        return Lambda<Handler>(callIfNotNull, parameterExpr).CompileFast();
    }
}

For 2.0.0 nuget:
image

For 5a3d4ba:
image
Didn't try to understand it, but looks overly complex (and failing while executing).

This is correct output of system Compile:
image

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions