Skip to content

Invalid Program after Coalesce #284

@ackava

Description

@ackava

Sample C# Code

        public class Variable
        {

            public string Name { get; set; }
            public Variable(string name)
            {
                Name = name;
            }
        }

    Func<Variable, string, Variable> fx  = (input, text) => {
         input = input ?? new Variable("default");
         input.Value = text;
        return input;
    };

Test Case

        public class Variable
        {

            public string Name { get; set; }
            public Variable(string name)
            {
                Name = name;
            }
        }


        [Test]
        public void CoalescFail()
        {
            var input = Parameter(typeof(Variable));
            var text = Parameter(typeof(string));
            var ctor = typeof(Variable).GetConstructor(new Type[] { typeof(string) });
            var property = typeof(Variable).GetProperty(nameof(Variable.Name));

            var lambda = Lambda(
                Block(
                Coalesce(input, New(ctor, Constant("default"))),
                Assign(Property(input, property), text),
                input), input, text);

            var t = lambda.ToExpressionString();

            var fx = lambda.CompileFast<Func<Variable, string,Variable>>();

            Assert.NotNull(fx(null,  "a"));
        }

It seems any statement after coalesc is failing.

If you look at this link, coalesc is done without loading null on to the stack. This could be improvement.

https://sharplab.io/#v2:C4LglgNgPgAgTARgLACgYGYAE9MGFMDeqmJ2WMALJgLIAUAlIcaQL7MntnYIBs3ADHgD2AQwgBTAM4BjWjASCwAOwAOAV2AAaAZgAmI4CMZEUpM9gDsmZeuCYA/Pb0GRDpwCIR7gNyc2p0lR/VCA

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions