Skip to content

Commit 568827f

Browse files
authored
Treat receivers as by-value for interpolated string handler constructors (#56864)
Fixes #56624.
1 parent b76af05 commit 568827f

File tree

4 files changed

+318
-208
lines changed

4 files changed

+318
-208
lines changed

src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,6 @@ private void CoerceArguments<TMember>(
29952995
ArrayBuilder<BoundExpression> arguments,
29962996
BindingDiagnosticBag diagnostics,
29972997
TypeSymbol? receiverType,
2998-
RefKind? receiverRefKind,
29992998
uint receiverEscapeScope)
30002999
where TMember : Symbol
30013000
{
@@ -3014,7 +3013,7 @@ private void CoerceArguments<TMember>(
30143013
Debug.Assert(argument is BoundUnconvertedInterpolatedString or BoundBinaryOperator { IsUnconvertedInterpolatedStringAddition: true });
30153014
TypeWithAnnotations parameterTypeWithAnnotations = GetCorrespondingParameterTypeWithAnnotations(ref result, parameters, arg);
30163015
reportUnsafeIfNeeded(methodResult, diagnostics, argument, parameterTypeWithAnnotations);
3017-
arguments[arg] = BindInterpolatedStringHandlerInMemberCall(argument, arguments, parameters, ref result, arg, receiverType, receiverRefKind, receiverEscapeScope, diagnostics);
3016+
arguments[arg] = BindInterpolatedStringHandlerInMemberCall(argument, arguments, parameters, ref result, arg, receiverType, receiverEscapeScope, diagnostics);
30183017
}
30193018
// https://github.com/dotnet/roslyn/issues/37119 : should we create an (Identity) conversion when the kind is Identity but the types differ?
30203019
else if (!kind.IsIdentity)
@@ -5723,7 +5722,7 @@ internal bool TryPerformConstructorOverloadResolution(
57235722

57245723
if (succeededIgnoringAccessibility)
57255724
{
5726-
this.CoerceArguments<MethodSymbol>(result.ValidResult, analyzedArguments.Arguments, diagnostics, receiverType: null, receiverRefKind: null, receiverEscapeScope: Binder.ExternalScope);
5725+
this.CoerceArguments<MethodSymbol>(result.ValidResult, analyzedArguments.Arguments, diagnostics, receiverType: null, receiverEscapeScope: Binder.ExternalScope);
57275726
}
57285727

57295728
// Fill in the out parameter with the result, if there was one; it might be inaccessible.
@@ -7967,7 +7966,7 @@ private BoundExpression BindIndexerOrIndexedPropertyAccess(
79677966
uint receiverEscapeScope = property.RequiresInstanceReceiver && receiverOpt != null
79687967
? receiverRefKind?.IsWritableReference() == true ? GetRefEscape(receiverOpt, LocalScopeDepth) : GetValEscape(receiverOpt, LocalScopeDepth)
79697968
: Binder.ExternalScope;
7970-
this.CoerceArguments<PropertySymbol>(resolutionResult, analyzedArguments.Arguments, diagnostics, receiverOpt?.Type, receiverRefKind, receiverEscapeScope);
7969+
this.CoerceArguments<PropertySymbol>(resolutionResult, analyzedArguments.Arguments, diagnostics, receiverOpt?.Type, receiverEscapeScope);
79717970

79727971
var isExpanded = resolutionResult.Result.Kind == MemberResolutionKind.ApplicableInExpandedForm;
79737972
var argsToParams = resolutionResult.Result.ArgsToParamsOpt;

src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ private BoundExpression BindInterpolatedStringHandlerInMemberCall(
766766
ref MemberAnalysisResult memberAnalysisResult,
767767
int interpolatedStringArgNum,
768768
TypeSymbol? receiverType,
769-
RefKind? receiverRefKind,
770769
uint receiverEscapeScope,
771770
BindingDiagnosticBag diagnostics)
772771
{
@@ -874,8 +873,8 @@ private BoundExpression BindInterpolatedStringHandlerInMemberCall(
874873
switch (argumentIndex)
875874
{
876875
case BoundInterpolatedStringArgumentPlaceholder.InstanceParameter:
877-
Debug.Assert(receiverRefKind != null && receiverType is not null);
878-
refKind = receiverRefKind.GetValueOrDefault();
876+
Debug.Assert(receiverType is not null);
877+
refKind = RefKind.None;
879878
placeholderType = receiverType;
880879
break;
881880
case BoundInterpolatedStringArgumentPlaceholder.UnspecifiedParameter:

src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ private BoundCall BindInvocationExpressionContinued(
10261026
uint receiverValEscapeScope = method.RequiresInstanceReceiver && receiver != null
10271027
? receiverRefKind?.IsWritableReference() == true ? GetRefEscape(receiver, LocalScopeDepth) : GetValEscape(receiver, LocalScopeDepth)
10281028
: Binder.ExternalScope;
1029-
this.CoerceArguments(methodResult, analyzedArguments.Arguments, diagnostics, receiver?.Type, receiverRefKind, receiverValEscapeScope);
1029+
this.CoerceArguments(methodResult, analyzedArguments.Arguments, diagnostics, receiver?.Type, receiverValEscapeScope);
10301030

10311031
var expanded = methodResult.Result.Kind == MemberResolutionKind.ApplicableInExpandedForm;
10321032
var argsToParams = methodResult.Result.ArgsToParamsOpt;
@@ -2033,7 +2033,6 @@ private BoundFunctionPointerInvocation BindFunctionPointerInvocation(SyntaxNode
20332033
analyzedArguments.Arguments,
20342034
diagnostics,
20352035
receiverType: null,
2036-
receiverRefKind: null,
20372036
receiverEscapeScope: Binder.ExternalScope);
20382037

20392038
var args = analyzedArguments.Arguments.ToImmutable();

0 commit comments

Comments
 (0)