Skip to content

Commit dcf567f

Browse files
committed
[mcs] Populate referencecontainer member-cache correctly. Fixes #60860
1 parent c1fd42e commit dcf567f

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

mcs/mcs/expression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9905,7 +9905,7 @@ public override bool HasConditionalAccess ()
99059905
public static bool IsValidDotExpression (TypeSpec type)
99069906
{
99079907
const MemberKind dot_kinds = MemberKind.Class | MemberKind.Struct | MemberKind.Delegate | MemberKind.Enum |
9908-
MemberKind.Interface | MemberKind.TypeParameter | MemberKind.ArrayType;
9908+
MemberKind.Interface | MemberKind.TypeParameter | MemberKind.ArrayType | MemberKind.ByRef;
99099909

99109910
return (type.Kind & dot_kinds) != 0 || type.BuiltinType == BuiltinTypeSpec.Type.Dynamic;
99119911
}

mcs/mcs/typespec.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,7 @@ class ReferenceContainer : ElementTypeSpec
20012001
ReferenceContainer (TypeSpec element)
20022002
: base (MemberKind.ByRef, element, null)
20032003
{
2004+
cache = null;
20042005
}
20052006

20062007
public override IList<TypeSpec> Interfaces {
@@ -2041,6 +2042,11 @@ public static ReferenceContainer MakeType (ModuleContainer module, TypeSpec elem
20412042

20422043
return pc;
20432044
}
2045+
2046+
protected override void InitializeMemberCache(bool onlyTypes)
2047+
{
2048+
cache = Element.MemberCache;
2049+
}
20442050
}
20452051

20462052
class PointerContainer : ElementTypeSpec

mcs/tests/known-issues-interp-net_4_x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ test-704.cs
1919
test-811.cs
2020
test-async-17.cs
2121
test-ref-08.cs IGNORE
22+
test-ref-09.cs IGNORE

mcs/tests/test-ref-09.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
struct rigidbody { public float x; }
2+
3+
class Program
4+
{
5+
static rigidbody a;
6+
static ref rigidbody property_returning_struct_by_ref => ref a;
7+
8+
static void Main()
9+
{
10+
System.Console.WriteLine (property_returning_struct_by_ref.x);
11+
}
12+
}

mcs/tests/ver-il-net_4_x.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72967,6 +72967,19 @@
7296772967
</method>
7296872968
</type>
7296972969
</test>
72970+
<test name="test-ref-09.cs">
72971+
<type name="Program">
72972+
<method name="rigidbody&amp; get_property_returning_struct_by_ref()" attrs="2193">
72973+
<size>13</size>
72974+
</method>
72975+
<method name="Void Main()" attrs="145">
72976+
<size>17</size>
72977+
</method>
72978+
<method name="Void .ctor()" attrs="6278">
72979+
<size>7</size>
72980+
</method>
72981+
</type>
72982+
</test>
7297072983
<test name="test-static-using-01.cs">
7297172984
<type name="A.B.X">
7297272985
<method name="Int32 Test()" attrs="150">

0 commit comments

Comments
 (0)