Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1361,14 +1361,16 @@ static bool bindMethodGroupInvocation(
var resolution = addMethodBinder.ResolveMethodGroup(
methodGroup, expression, WellKnownMemberNames.CollectionInitializerAddMethodName, analyzedArguments,
useSiteInfo: ref useSiteInfo,
options: OverloadResolution.Options.DynamicResolution | OverloadResolution.Options.DynamicConvertsToAnything);
options: OverloadResolution.Options.DynamicResolution | OverloadResolution.Options.DynamicConvertsToAnything,
acceptOnlyMethods: true);

diagnostics.Add(expression, useSiteInfo);

if (!methodGroup.HasAnyErrors) diagnostics.AddRange(resolution.Diagnostics); // Suppress cascading.

if (resolution.IsNonMethodExtensionMember(out Symbol? extensionMember))
{
Debug.Assert(false); // Should not get here given the 'acceptOnlyMethods' argument value used in 'ResolveMethodGroup' call above
ReportMakeInvocationExpressionBadMemberKind(syntax, WellKnownMemberNames.CollectionInitializerAddMethodName, methodGroup, diagnostics);
addMethods = [];
result = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ private BoundExpression MakeDeconstructInvocationExpression(
// Those placeholders are also recorded in the outVar for easy access below, by the `SetInferredType` call on the outVar nodes.
BoundExpression result = BindMethodGroupInvocation(
rightSyntax, rightSyntax, methodName, (BoundMethodGroup)memberAccess, analyzedArguments, diagnostics, queryClause: null,
ignoreNormalFormIfHasValidParamsParameter: false, anyApplicableCandidates: out anyApplicableCandidates);
ignoreNormalFormIfHasValidParamsParameter: false, anyApplicableCandidates: out anyApplicableCandidates,
disallowExpandedNonArrayParams: false, acceptOnlyMethods: true);

result.WasCompilerGenerated = true;

Expand Down
21 changes: 17 additions & 4 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7994,7 +7994,7 @@ private BoundExpression MakeMemberAccessValue(BoundExpression expr, BindingDiagn
// Note: we're resolving without arguments, which means we're not treating the member access as invoked
var resolution = this.ResolveExtension(
syntax, name, analyzedArguments: null, receiver, typeArgumentsOpt, options: OverloadResolution.Options.None,
returnRefKind: default, returnType: null, ref useSiteInfo);
returnRefKind: default, returnType: null, ref useSiteInfo, acceptOnlyMethods: false);

diagnostics.Add(syntax, useSiteInfo);

Expand Down Expand Up @@ -8492,6 +8492,7 @@ protected MethodGroupResolution ResolveExtension(
RefKind returnRefKind,
TypeSymbol? returnType,
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo,
bool acceptOnlyMethods,
in CallingConventionInfo callingConvention = default)
{
Debug.Assert(left.Type is not null);
Expand Down Expand Up @@ -8534,6 +8535,7 @@ protected MethodGroupResolution ResolveExtension(
typeArgumentsWithAnnotations, returnType, returnRefKind, lookupResult,
analyzedArguments, ref actualMethodArguments, ref actualReceiverArguments, ref useSiteInfo, ref firstResult,
options, callingConvention, classicExtensionLookupResult, lookupOptions, binder: this, scope: scope, diagnostics: diagnostics,
acceptOnlyMethods: acceptOnlyMethods,
result: out MethodGroupResolution result))
{
lookupResult.Free();
Expand Down Expand Up @@ -8582,6 +8584,7 @@ static bool tryResolveExtensionInScope(
LookupOptions lookupOptions,
Binder binder,
ExtensionScope scope,
bool acceptOnlyMethods,
BindingDiagnosticBag diagnostics,
out MethodGroupResolution result)
{
Expand Down Expand Up @@ -8610,7 +8613,9 @@ static bool tryResolveExtensionInScope(

// 3. resolve properties
Debug.Assert(arity == 0 || lookupResult.Symbols.All(s => s.Kind != SymbolKind.Property));
OverloadResolutionResult<PropertySymbol>? propertyResult = arity != 0 ? null : resolveProperties(left, lookupResult, binder, ref actualReceiverArguments, ref useSiteInfo);

// PROTOTYPE: Regarding 'acceptOnlyMethods', consider if it would be better to add a special 'LookupOptions' value to filter out properties during lookup
OverloadResolutionResult<PropertySymbol>? propertyResult = arity != 0 || acceptOnlyMethods ? null : resolveProperties(left, lookupResult, binder, ref actualReceiverArguments, ref useSiteInfo);

// 4. determine member kind
if (!methodResult.HasAnyApplicableMethod && propertyResult?.HasAnyApplicableMember != true)
Expand Down Expand Up @@ -10465,7 +10470,9 @@ void makeCall(SyntaxNode syntax, BoundExpression receiver, MethodSymbol method,
{ WasCompilerGenerated = true };

indexerOrSliceAccess = BindMethodGroupInvocation(syntax, syntax, method.Name, boundMethodGroup, analyzedArguments,
diagnostics, queryClause: null, ignoreNormalFormIfHasValidParamsParameter: true, anyApplicableCandidates: out bool _).MakeCompilerGenerated();
diagnostics, queryClause: null, ignoreNormalFormIfHasValidParamsParameter: true, anyApplicableCandidates: out bool _,
disallowExpandedNonArrayParams: false,
acceptOnlyMethods: true).MakeCompilerGenerated(); // PROTOTYPE: Test effect of acceptOnlyMethods value

analyzedArguments.Free();
}
Expand Down Expand Up @@ -10593,7 +10600,9 @@ internal MethodGroupResolution ResolveMethodGroup(

return ResolveMethodGroup(
node, node.Syntax, node.Name, analyzedArguments, ref useSiteInfo,
options, returnRefKind: returnRefKind, returnType: returnType,
options,
acceptOnlyMethods: true, // PROTOTYPE: Confirm this value is appropriate for all consumers of the enclosing method and test effect of this value for all of them
returnRefKind: returnRefKind, returnType: returnType,
callingConventionInfo: callingConventionInfo);
}

Expand All @@ -10604,13 +10613,15 @@ internal MethodGroupResolution ResolveMethodGroup(
AnalyzedArguments analyzedArguments,
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo,
OverloadResolution.Options options,
bool acceptOnlyMethods,
RefKind returnRefKind = default,
TypeSymbol returnType = null,
in CallingConventionInfo callingConventionInfo = default)
{
var methodResolution = ResolveMethodGroupInternal(
node, expression, memberName, analyzedArguments, ref useSiteInfo,
options,
acceptOnlyMethods: acceptOnlyMethods,
returnRefKind: returnRefKind, returnType: returnType,
callingConvention: callingConventionInfo);
if (methodResolution.IsEmpty && !methodResolution.HasAnyErrors)
Expand All @@ -10634,6 +10645,7 @@ private MethodGroupResolution ResolveMethodGroupInternal(
AnalyzedArguments analyzedArguments,
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo,
OverloadResolution.Options options,
bool acceptOnlyMethods,
RefKind returnRefKind = default,
TypeSymbol returnType = null,
in CallingConventionInfo callingConvention = default)
Expand All @@ -10653,6 +10665,7 @@ private MethodGroupResolution ResolveMethodGroupInternal(
var extensionMethodResolution = ResolveExtension(
expression, memberName, analyzedArguments, methodGroup.ReceiverOpt, methodGroup.TypeArgumentsOpt, options,
returnRefKind: returnRefKind, returnType: returnType, ref useSiteInfo,
acceptOnlyMethods: acceptOnlyMethods,
in callingConvention);
bool preferExtensionMethodResolution = false;

Expand Down
9 changes: 6 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ private BoundExpression BindInvocationExpression(
diagnostics, queryClause,
ignoreNormalFormIfHasValidParamsParameter: ignoreNormalFormIfHasValidParamsParameter,
disallowExpandedNonArrayParams: disallowExpandedNonArrayParams,
anyApplicableCandidates: out _);
anyApplicableCandidates: out _,
acceptOnlyMethods: false);
}
else if ((object)(delegateType = GetDelegateType(boundExpression)) != null)
{
Expand Down Expand Up @@ -696,7 +697,8 @@ private BoundExpression BindMethodGroupInvocation(
CSharpSyntaxNode queryClause,
bool ignoreNormalFormIfHasValidParamsParameter,
out bool anyApplicableCandidates,
bool disallowExpandedNonArrayParams = false)
bool disallowExpandedNonArrayParams,
bool acceptOnlyMethods) // For example, do not accept extension property value invocations (delegates returned by a property can be invoked, etc.)
{
//
// !!! ATTENTION !!!
Expand All @@ -713,7 +715,8 @@ private BoundExpression BindMethodGroupInvocation(
useSiteInfo: ref useSiteInfo,
options: (ignoreNormalFormIfHasValidParamsParameter ? OverloadResolution.Options.IgnoreNormalFormIfHasValidParamsParameter : OverloadResolution.Options.None) |
(disallowExpandedNonArrayParams ? OverloadResolution.Options.DisallowExpandedNonArrayParams : OverloadResolution.Options.None) |
(analyzedArguments.HasDynamicArgument ? OverloadResolution.Options.DynamicResolution : OverloadResolution.Options.None));
(analyzedArguments.HasDynamicArgument ? OverloadResolution.Options.DynamicResolution : OverloadResolution.Options.None),
acceptOnlyMethods: acceptOnlyMethods);
diagnostics.Add(expression, useSiteInfo);

if (resolution.IsNonMethodExtensionMember(out Symbol extensionMember))
Expand Down
6 changes: 4 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ internal MethodSymbol TryFindDisposePatternMethod(BoundExpression expr, SyntaxNo
out var disposeMethod,
out isExpanded);

if (disposeMethod?.IsExtensionMethod == true)
if (disposeMethod is not null && (disposeMethod.IsExtensionMethod || disposeMethod.GetIsNewExtensionMember()))
{
// Extension methods should just be ignored, rather than rejected after-the-fact
// Tracked by https://github.com/dotnet/roslyn/issues/32767
Expand Down Expand Up @@ -4153,7 +4153,9 @@ internal PatternLookupResult PerformPatternMethodLookup(BoundExpression receiver
bindingDiagnostics,
queryClause: null,
ignoreNormalFormIfHasValidParamsParameter: true,
anyApplicableCandidates: out _);
anyApplicableCandidates: out _,
disallowExpandedNonArrayParams: false,
acceptOnlyMethods: true);

analyzedArguments.Free();

Expand Down
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/ForEachLoopBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,8 @@ private MethodArgumentInfo FindForEachPatternMethodViaExtension(SyntaxNode synta
options: OverloadResolution.Options.None,
returnRefKind: default,
returnType: null,
ref extensionUseSiteInfo);
ref extensionUseSiteInfo,
acceptOnlyMethods: true); // PROTOTYPE: Test effect of acceptOnlyMethods value

diagnostics.Add(syntax, extensionUseSiteInfo);
diagnostics.AddRange(methodGroupResolutionResult.Diagnostics);
Expand Down
Loading
Loading