Skip to content

Commit

Permalink
Tweak cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Jul 13, 2022
1 parent b5175e8 commit 3442215
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
10 changes: 1 addition & 9 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4685,17 +4685,9 @@ private BoundExpression BindInitializerMemberAssignment(
{
Debug.Assert((object)boundLeft.Type != null);

BindValueKind rhsKind;
var rhsExpr = initializer.Right.CheckAndUnwrapRefExpression(diagnostics, out RefKind refKind);
bool isRef = refKind == RefKind.Ref;
if (isRef && !boundLeft.HasErrors)
{
rhsKind = GetRequiredRHSValueKindForRefAssignment(boundLeft);
}
else
{
rhsKind = BindValueKind.RValue;
}
var rhsKind = isRef ? GetRequiredRHSValueKindForRefAssignment(boundLeft) : BindValueKind.RValue;

// Bind member initializer value, i.e. right part of assignment
BoundExpression boundRight = BindInitializerExpressionOrValue(
Expand Down
27 changes: 10 additions & 17 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,16 +1463,7 @@ private BoundExpression BindAssignment(AssignmentExpressionSyntax node, BindingD
var op1 = BindValue(node.Left, diagnostics, lhsKind);
ReportSuppressionIfNeeded(op1, diagnostics);

BindValueKind rhsKind;
if (lhsKind == BindValueKind.RefAssignable && !op1.HasErrors)
{
rhsKind = GetRequiredRHSValueKindForRefAssignment(op1);
}
else
{
rhsKind = BindValueKind.RValue;
}

var rhsKind = isRef ? GetRequiredRHSValueKindForRefAssignment(op1) : BindValueKind.RValue;
var op2 = BindValue(rhsExpr, diagnostics, rhsKind);

if (op1.Kind == BoundKind.DiscardExpression)
Expand All @@ -1486,16 +1477,18 @@ private BoundExpression BindAssignment(AssignmentExpressionSyntax node, BindingD

private static BindValueKind GetRequiredRHSValueKindForRefAssignment(BoundExpression boundLeft)
{
Debug.Assert(!boundLeft.HasErrors);
var rhsKind = BindValueKind.RefersToLocation;

// We should now know that boundLeft is a valid lvalue
var lhsRefKind = boundLeft.GetRefKind();
if (lhsRefKind is RefKind.Ref or RefKind.Out)
if (!boundLeft.HasErrors)
{
// If the LHS is a ref (not ref-readonly), the rhs
// must also be value-assignable
rhsKind |= BindValueKind.Assignable;
// We should now know that boundLeft is a valid lvalue
var lhsRefKind = boundLeft.GetRefKind();
if (lhsRefKind is RefKind.Ref or RefKind.Out)
{
// If the LHS is a ref (not ref-readonly), the rhs
// must also be value-assignable
rhsKind |= BindValueKind.Assignable;
}
}

return rhsKind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,6 @@ public struct Thing
[Fact, WorkItem(26457, "https://github.com/dotnet/roslyn/issues/26457")]
public void RefThisAssignment_Class()
{
// TODO2 regression with `this`
CreateCompilation(@"
class Test
{
Expand Down

0 comments on commit 3442215

Please sign in to comment.