Skip to content

InvalidProgramException when nullable result is ignored #310

@exyi

Description

@exyi

The error occurs when I have a Convert expression returning Nullable, but I ignore the result. For example

[Test]
public void Case2_A()
{
  var p = Parameter(typeof(int), "tmp0");
  var expr = 
    Lambda<Action<int>>(Block(
      Convert(p, typeof(int?)),
      Default(typeof(void))), p);

  var f = expr.CompileFast();
  f(2);
}

Or similar:

[Test]
public void Case2_B()
{
  var p = Parameter(typeof(int), "tmp0");
  var expr = 
    Lambda<Action<int>>(Convert(p, typeof(int?)), new[] { p });
  var f = expr.CompileFast();
  f(2);
}

In these simple cases, I could just not place the ignored convert there, but it also fails in more complex cases when the conversion is nested in conditions/blocks, but the result is still not used in the end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions