Skip to content

Commit

Permalink
added last case from the #415
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Jun 26, 2024
1 parent f2b50be commit 147c57f
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ public int Run()
// ReturnRefParameter();
// PassByRefParameter();
#if LIGHT_EXPRESSION
Issue415_ReturnRefParameterByRef();
// Issue415_ReturnRefParameterByRef();
Issue415_ReturnRefParameterByRef_ReturnRefCall();
// PassByRefVariable();
return 3;
#else
return 2;
#endif
}

public delegate int MyDelegate(ref int x);
delegate int MyDelegate(ref int x);

[Test]
public void ReturnRefParameter()
Expand Down Expand Up @@ -115,6 +116,32 @@ public void Issue415_ReturnRefParameterByRef()
++ff(ref x);
Assert.AreEqual(18, x);
}


public static ref int ReturnRef(ref int x) => ref x;

[Test]
public void Issue415_ReturnRefParameterByRef_ReturnRefCall()
{
var p = Parameter(typeof(int).MakeByRefType());
var expr = Lambda<MyDelegateByRef>(
Expression.Call(GetType().GetMethod(nameof(ReturnRef)), p),
p);

expr.PrintCSharp();

var ff = expr.CompileFast(true, CompilerFlags.ThrowOnNotSupportedExpression);
ff.PrintIL();

// ff.AssertOpCodes(
// OpCodes.Ldarg_1,
// OpCodes.Ret
// );

var x = 17;
++ff(ref x);
Assert.AreEqual(18, x);
}

delegate int MyDelegateNoPars();

Expand Down

0 comments on commit 147c57f

Please sign in to comment.