Skip to content

Commit

Permalink
Fix duplicate local issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Aug 21, 2021
1 parent adb4c64 commit 50605e9
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,14 @@ private BoundExpression MakeDynamicCollectionInitializer(BoundExpression rewritt
return MakeCall(null, syntax, rewrittenReceiver, addMethod, rewrittenArguments, argumentRefKindsOpt, initializer.InvokedAsExtensionMethod, initializer.ResultKind, addMethod.ReturnType, temps.ToImmutableAndFree());
}

public BoundExpression VisitObjectInitializerMember(BoundObjectInitializerMember node, ref BoundExpression rewrittenReceiver, ArrayBuilder<BoundExpression> sideEffects, ref ArrayBuilder<LocalSymbol>? temps)
private BoundExpression VisitObjectInitializerMember(BoundObjectInitializerMember node, ref BoundExpression rewrittenReceiver, ArrayBuilder<BoundExpression> sideEffects, ref ArrayBuilder<LocalSymbol>? temps)
{
if (node.MemberSymbol is null)
{
return (BoundExpression)base.VisitObjectInitializerMember(node)!;
}

var originalReceiver = rewrittenReceiver;
var rewrittenArguments = VisitArguments(node.Arguments, node.MemberSymbol, node.ArgsToParamsOpt, node.ArgumentRefKindsOpt, ref rewrittenReceiver, out ArrayBuilder<LocalSymbol>? constructionTemps);

if (constructionTemps != null)
Expand All @@ -229,7 +230,7 @@ public BoundExpression VisitObjectInitializerMember(BoundObjectInitializerMember
}
}

if (rewrittenReceiver is BoundSequence sequence)
if (originalReceiver != rewrittenReceiver && rewrittenReceiver is BoundSequence sequence)
{
Debug.Assert(temps != null);
temps.AddRange(sequence.Locals);
Expand Down

0 comments on commit 50605e9

Please sign in to comment.