From: Marek Safar Date: Tue, 3 Oct 2017 00:27:20 +0000 (+0200) Subject: [mcs] Allow properties and indexers of by-ref values to be set without setter X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=adaf7fd65b9a53a8e127d41bf430e56001c6e472 [mcs] Allow properties and indexers of by-ref values to be set without setter --- diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index 490bcfb518e..34ff9a30dab 100644 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -7394,6 +7394,11 @@ namespace Mono.CSharp { if (ResolveAutopropertyAssignment (rc, right_side)) return this; + if (best_candidate.MemberType.Kind == MemberKind.ByRef) { + getter = CandidateToBaseOverride (rc, best_candidate.Get); + return ByRefDereference.Create(this).Resolve(rc); + } + rc.Report.Error (200, loc, "Property or indexer `{0}' cannot be assigned to (it is read-only)", GetSignatureForError ()); return null; diff --git a/mcs/tests/test-ref-06.cs b/mcs/tests/test-ref-06.cs new file mode 100644 index 00000000000..74d35f44ed8 --- /dev/null +++ b/mcs/tests/test-ref-06.cs @@ -0,0 +1,24 @@ +using System; + +class X +{ + public static int Main () + { + var x = new X (); + x [0] = 3; + if (x.field != 3) + return 1; + x.Prop = 5; + if (x.field != 5) + return 2; + + return 0; + } + + int field; + + ref int this [int idx] => ref field; + + ref int Prop => ref field; + +} \ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index b111a7e3c5a..16a62d1ce87 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -72780,6 +72780,22 @@ + + + + 71 + + + 14 + + + 14 + + + 7 + + +