Skip to content

Commit

Permalink
Allow accessing ref fields through rvalues (#75316)
Browse files Browse the repository at this point in the history
* Allow accessing ref fields through rvalues

* Remove unnecessary block
  • Loading branch information
jjonescz authored Oct 3, 2024
1 parent 8e4dab3 commit 0d41e66
Show file tree
Hide file tree
Showing 2 changed files with 401 additions and 24 deletions.
15 changes: 15 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,21 @@ private bool CheckFieldValueKind(SyntaxNode node, BoundFieldAccess fieldAccess,
}
}

if (RequiresReferenceToLocation(valueKind))
{
switch (fieldSymbol.RefKind)
{
case RefKind.None:
break;
case RefKind.Ref:
case RefKind.RefReadOnly:
// ref readonly access to a ref (readonly) field is fine regardless of the receiver
return true;
default:
throw ExceptionUtilities.UnexpectedValue(fieldSymbol.RefKind);
}
}

// r/w fields that are static or belong to reference types are writeable and returnable
if (fieldSymbol.IsStatic || fieldSymbol.ContainingType.IsReferenceType)
{
Expand Down
Loading

0 comments on commit 0d41e66

Please sign in to comment.