Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Params side of the design changes around Add methods #72771

Merged
merged 7 commits into from
Mar 29, 2024
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 @@ -368,7 +368,7 @@ private BoundIndexerAccess BindIndexerDefaultArgumentsAndParamsCollection(BoundI
}
}

BindDefaultArgumentsAndParamsCollection(indexerAccess.Syntax, parameters, argumentsBuilder, refKindsBuilderOpt, namesBuilder, ref argsToParams, out defaultArguments, indexerAccess.Expanded, enableCallerInfo: true, diagnostics);
BindDefaultArguments(indexerAccess.Syntax, parameters, argumentsBuilder, refKindsBuilderOpt, namesBuilder, ref argsToParams, out defaultArguments, indexerAccess.Expanded, enableCallerInfo: true, diagnostics);

if (namesBuilder is object)
{
Expand Down
12 changes: 8 additions & 4 deletions src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a
Binder attributeArgumentBinder = this.WithAdditionalFlags(BinderFlags.AttributeArgument);
AnalyzedAttributeArguments analyzedArguments = attributeArgumentBinder.BindAttributeArguments(argumentListOpt, attributeTypeForBinding, diagnostics);

ImmutableArray<int> argsToParamsOpt = default;
ImmutableArray<int> argsToParamsOpt;
bool expanded = false;
BitVector defaultArguments = default;
MethodSymbol? attributeConstructor = null;
Expand All @@ -191,6 +191,7 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a
boundConstructorArguments = analyzedArguments.ConstructorArguments.Arguments.SelectAsArray(
static (arg, attributeArgumentBinder) => attributeArgumentBinder.BindToTypeForErrorRecovery(arg),
attributeArgumentBinder);
argsToParamsOpt = default;
}
else
{
Expand All @@ -210,12 +211,15 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a

if (memberResolutionResult.IsNotNull)
{
this.CheckAndCoerceArguments<MethodSymbol>(memberResolutionResult, analyzedArguments.ConstructorArguments, diagnostics, receiver: null, invokedAsExtensionMethod: false);
this.CheckAndCoerceArguments<MethodSymbol>(node, memberResolutionResult, analyzedArguments.ConstructorArguments, diagnostics, receiver: null, invokedAsExtensionMethod: false, out argsToParamsOpt);
}
else
{
argsToParamsOpt = memberResolutionResult.Result.ArgsToParamsOpt;
}

attributeConstructor = memberResolutionResult.Member;
expanded = memberResolutionResult.Resolution == MemberResolutionKind.ApplicableInExpandedForm;
argsToParamsOpt = memberResolutionResult.Result.ArgsToParamsOpt;

if (!found)
{
Expand All @@ -229,7 +233,7 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a
}
else
{
attributeArgumentBinder.BindDefaultArgumentsAndParamsCollection(
attributeArgumentBinder.BindDefaultArguments(
node,
attributeConstructor.Parameters,
analyzedArguments.ConstructorArguments.Arguments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ static bool bindMethodGroupInvocation(
out ImmutableArray<MethodSymbol> addMethods)
{
Debug.Assert(methodGroup.ReceiverOpt is not null);
Debug.Assert(methodGroup.ReceiverOpt.Type is not null);

bool result;
CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = addMethodBinder.GetNewCompoundUseSiteInfo(diagnostics);
Expand Down Expand Up @@ -1129,6 +1130,11 @@ static bool bindMethodGroupInvocation(

addMethods = filterOutBadGenericMethods(addMethodBinder, syntax, methodGroup, analyzedArguments, resolution, finalApplicableCandidates, ref useSiteInfo);
result = !addMethods.IsEmpty;

if (!result)
{
diagnostics.Add(ErrorCode.ERR_CollectionExpressionMissingAdd, syntax, methodGroup.ReceiverOpt.Type);
}
}
}
else
Expand Down Expand Up @@ -1550,7 +1556,6 @@ private void GenerateImplicitConversionErrorForCollectionExpression(
if (elements.Length > 0 &&
!HasCollectionExpressionApplicableAddMethod(node.Syntax, targetType, addMethods: out _, diagnostics))
{
Error(diagnostics, ErrorCode.ERR_CollectionExpressionMissingAdd, node.Syntax, targetType);
reportedErrors = true;
}
}
Expand Down
Loading