-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic binders fails to properly assign values to by-ref properties or indexers #24621
Comments
@VSadov Please label and triage as appropriate. Thanks |
Problem 1. The dynamic binder can't create a valid tree because the expression produced would have to work on a property of with the same type as (using constant expressions for simplicity): Expression.MakeIndex(Expression.Constant(c),
typeof(C).GetProperties()[0],
new[] { Expression.Constant(1)}) That throws an Problem 2. If it was allowed it wouldn't be considered an lvalue, so the lvalue rules would have to be changed to consider get-only properties (and for that matter, methods) which return references as lvalues. Problem 3A. The IL generation would need changes to handle those cases. Problem 3B. The interpreter tries to do property-gets through Only when S.L.Expressions can handle such expressions will it be worth changing MS.CSharp to produce them. |
Right. We may have to split this into two bugs -
As for support in interpreter - that is not possible now. That would need new reflection APIs. In general reflection APIs are not awesome for byrefs - even for parameters. Anyone who tried to call Interlocked.CompareExchange via reflection/interpreter knows that. :-/ |
Another variant is assigning to ref-returning methods. With: public class C
{
public static int val;
public ref int AccessVal(int _) => ref val;
}
void Main()
{
var d = new C();
dynamic p = 2;
d.AccessVal(p) = 2;
Console.WriteLine(C.val);
} The static compiler sees this as if |
Looking into the expressions part of this raises some further issues. In particular if we don't include explicit |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
This issue will now be closed since it had been marked |
@VladimirReshetnikov commented on Tue Mar 14 2017
Version Used:
Microsoft Visual Studio Community 2017
Version 15.0.26228.4 D15RTWSVC
Microsoft .NET Framework
Version 4.6.01586
Steps to Reproduce:
Compile and run:
Expected Behavior: Indexer assignment is performed successfully. If it is not feasible for some reason, then the compiler should give a compile-time error in cases like this, rather than allowing program to fail at runtime.
Actual Behavior:
@gafter commented on Tue Mar 14 2017
@VSadov What is the appropriate repo for filing bugs against the dynamic runtime?
@VSadov commented on Wed Mar 15 2017
C# Binder lives in CoreFX.
However, this repro should probably be a compile error - we statically know it in not going to work.
@jcouv commented on Wed Dec 27 2017
@VSadov Can you triage relative to your other assigned issues?
@VSadov commented on Thu Jan 04 2018
After thinking about this, it might be possible to fix the binder/expressions to understand such assignments.
Ref assignments are tricky and will require special APIs, but regular assignments are just assignments and should be completely representable in existing trees. Most likely it only needs that factories allow ref members as assignment targets, and make ET compiler do indirect assignments.
@VSadov commented on Mon Jan 08 2018
We should fix this in the dynamic binder.
This should be moved to CoreFx
The text was updated successfully, but these errors were encountered: