Closed
Description
Consider a byref method such as this constructor:
private class ByRefNewType
{
public ByRefNewType(ref int a, ref int b)
{
++a;
b *= a;
}
}
And a variable int x = 3
Calling new ByRefNewType(ref x, ref x)
is equivalent to running ++x; x*=x
and hence x
is 16.
With an expression-created delegate:
var del = Expression.Lambda<ByRefNewFactory2>(
Expression.New(
typeof(ByRefNewType).GetConstructors()[0], pX, pY),
pX, pY).Compile();
int x = 3;
del(byref x, byref x);
Then with the compiler x
will be 16 as expected, by with the interpreter y
will be 12 (it could conceivably end up being 4).
The cause is that the interpreter doesn't have true reference types and so the aliasing is broken.
I'm not sure this is feasibly fixable. It may have to be merely noted as a limitation.