Skip to content

Commit b01529a

Browse files
authored
Refactor/cleanup usages of MakeCallWithNoExplicitArgument helper (#78273)
1 parent c195a1f commit b01529a

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForEachStatement.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ private BoundStatement RewriteForEachEnumerator(
180180
}
181181

182182
// ((C)(x)).GetEnumerator(); OR (x).GetEnumerator(); OR async variants (which fill-in arguments for optional parameters)
183-
BoundExpression enumeratorVarInitValue = SynthesizeCall(getEnumeratorInfo, forEachSyntax, receiver,
184-
allowExtensionAndOptionalParameters: isAsync || getEnumeratorInfo.Method.IsExtensionMethod || getEnumeratorInfo.Method.GetIsNewExtensionMember(), firstRewrittenArgument: firstRewrittenArgument);
183+
BoundExpression enumeratorVarInitValue = MakeCall(getEnumeratorInfo, forEachSyntax, receiver,
184+
firstRewrittenArgument: firstRewrittenArgument);
185185

186186
// E e = ((C)(x)).GetEnumerator();
187187
BoundStatement enumeratorVarDecl = MakeLocalDeclaration(forEachSyntax, enumeratorVar, enumeratorVarInitValue);
@@ -214,11 +214,10 @@ private BoundStatement RewriteForEachEnumerator(
214214
// }
215215

216216
var rewrittenBodyBlock = CreateBlockDeclaringIterationVariables(iterationVariables, iterationVarDecl, rewrittenBody, forEachSyntax);
217-
BoundExpression rewrittenCondition = SynthesizeCall(
217+
BoundExpression rewrittenCondition = MakeCall(
218218
methodArgumentInfo: enumeratorInfo.MoveNextInfo,
219219
syntax: forEachSyntax,
220-
receiver: boundEnumeratorVar,
221-
allowExtensionAndOptionalParameters: isAsync,
220+
expression: boundEnumeratorVar,
222221
firstRewrittenArgument: null);
223222

224223
var disposalFinallyBlock = GetDisposalFinallyBlock(forEachSyntax, enumeratorInfo, enumeratorType, boundEnumeratorVar, out var hasAsyncDisposal);
@@ -369,7 +368,7 @@ private bool TryGetDisposeMethod(SyntaxNode forEachSyntax, ForEachEnumeratorInfo
369368
}
370369

371370
// ((IDisposable)e).Dispose() or e.Dispose() or await ((IAsyncDisposable)e).DisposeAsync() or await e.DisposeAsync()
372-
disposeCall = MakeCallWithNoExplicitArgument(disposeInfo, forEachSyntax, receiver, firstRewrittenArgument: null);
371+
disposeCall = MakeCall(disposeInfo, forEachSyntax, receiver, firstRewrittenArgument: null);
373372

374373
BoundStatement disposeCallStatement;
375374
var disposeAwaitableInfoOpt = enumeratorInfo.DisposeAwaitableInfo;
@@ -535,19 +534,6 @@ private BoundExpression ConvertReceiverForInvocation(CSharpSyntaxNode syntax, Bo
535534
return receiver;
536535
}
537536

538-
private BoundExpression SynthesizeCall(MethodArgumentInfo methodArgumentInfo, CSharpSyntaxNode syntax, BoundExpression? receiver, bool allowExtensionAndOptionalParameters, BoundExpression? firstRewrittenArgument)
539-
{
540-
if (allowExtensionAndOptionalParameters)
541-
{
542-
// Generate a call with zero explicit arguments, but with implicit arguments for optional and params parameters.
543-
return MakeCallWithNoExplicitArgument(methodArgumentInfo, syntax, receiver, firstRewrittenArgument: firstRewrittenArgument);
544-
}
545-
546-
// Generate a call with literally zero arguments
547-
Debug.Assert(methodArgumentInfo.Arguments.IsEmpty);
548-
return BoundCall.Synthesized(syntax, receiver, initialBindingReceiverIsSubjectToCloning: ThreeState.Unknown, methodArgumentInfo.Method, arguments: ImmutableArray<BoundExpression>.Empty);
549-
}
550-
551537
/// <summary>
552538
/// Lower a foreach loop that will enumerate a collection via indexing.
553539
///

src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UsingStatement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ private BoundExpression GenerateDisposeCall(
470470
disposeInfo = MethodArgumentInfo.CreateParameterlessMethod(disposeMethod);
471471
}
472472

473-
disposeCall = MakeCallWithNoExplicitArgument(disposeInfo, resourceSyntax, disposedExpression, firstRewrittenArgument: null);
473+
disposeCall = MakeCall(disposeInfo, resourceSyntax, disposedExpression, firstRewrittenArgument: null);
474474

475475
if (awaitOpt is object)
476476
{
@@ -489,7 +489,7 @@ private BoundExpression GenerateDisposeCall(
489489
/// Synthesize a call `expression.Method()`, but with some extra smarts to handle extension methods. This call expects that the
490490
/// receiver parameter has already been visited.
491491
/// </summary>
492-
private BoundExpression MakeCallWithNoExplicitArgument(MethodArgumentInfo methodArgumentInfo, SyntaxNode syntax, BoundExpression? expression, BoundExpression? firstRewrittenArgument)
492+
private BoundExpression MakeCall(MethodArgumentInfo methodArgumentInfo, SyntaxNode syntax, BoundExpression? expression, BoundExpression? firstRewrittenArgument)
493493
{
494494
MethodSymbol method = methodArgumentInfo.Method;
495495

0 commit comments

Comments
 (0)