There is no way to make a reflection call to a method with ref parameters while preserving aliasing nature of ref #15663
Labels
api-needs-work
API needs work before it is approved, it is NOT ready for implementation
area-System.Reflection
help wanted
[up-for-grabs] Good issue for external contributors
Milestone
VSadov: while passing parameters byref can be modeled through passing mutable object[] + copybacks. It is not the same as truly passing arguments byref.
Some methods, like ones from Interlocked family, rely on aliasing nature of ref and the difference is observable.
Since all the calls in Interpreter are done via reflection, we cannot interpret certain calls correctly due to insufficient APIs.
==============
Unlike the expression compiler where address-obtaining instructions are used to call by reference, the expression interpreter has to perform copy operations in and out of an arguments array upon calling the
Invoke
method. As a result, calls to constructs likeInterlocked
methods don't have the intended effect. An example repro is shown below:One would expect f(N) to return 2 * N. This is the case for the compiler, but not for the interpreter.
The text was updated successfully, but these errors were encountered: