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

Make trivial Params Collections scenarios working end to end #71136

Merged

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

@AlekseyTs AlekseyTs requested review from a team as code owners December 6, 2023 23:25
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 6, 2023
@AlekseyTs
Copy link
Contributor Author

@RikkiGibson, @333fred, @dotnet/roslyn-compiler Please review

{
var type = parameter.Type;
if (result.Kind == MemberResolutionKind.ApplicableInExpandedForm &&
parameter.IsParams && type.IsSZArray())
parameter.Ordinal == parameterCount - 1)
Copy link
Contributor

@RikkiGibson RikkiGibson Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This change relates to issue #70908. The parameter can differ on params modifier on virtual and override methods, for example, so checking ApplicableAndExpandedForm and Ordinal is complete and more robust than checking IsParams on a single symbol. #Resolved

@@ -368,7 +368,7 @@ private BoundIndexerAccess BindIndexerDefaultArgumentsAndParamsArray(BoundIndexe
}
}

BindDefaultArgumentsAndParamsArray(indexerAccess.Syntax, parameters, argumentsBuilder, refKindsBuilderOpt, namesBuilder, ref argsToParams, out defaultArguments, indexerAccess.Expanded, enableCallerInfo: true, diagnostics);
Copy link
Contributor

@RikkiGibson RikkiGibson Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also adjusting the name of BindIndexerDefaultArgumentsAndParamsArray. #Resolved

@@ -6602,15 +6602,24 @@ static void expandParamsArray(ref ImmutableArray<BoundExpression> arguments, ref
// At the moment, there is only one test that gets here like that - Microsoft.CodeAnalysis.CSharp.UnitTests.AttributeTests.TestBadParamsCtor.
// And we get here for the erroneous attribute application, constructor is inaccessible.
// Perhaps that shouldn't cancel the default values / params array processing?
Debug.Assert(arguments.Count(a => a.IsParamsArray) <= 1);
Debug.Assert(arguments.Count(a => a.IsParamsCollection) <= 1);
Copy link
Contributor

@RikkiGibson RikkiGibson Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming function expandParamsArray. #Resolved

}
else
{
elements = ((BoundCollectionExpression)((BoundConversion)argument).Operand).UnconvertedCollectionExpression.Elements.CastArray<BoundExpression>();
Copy link
Contributor

@RikkiGibson RikkiGibson Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests showing that NullableWalker is correctly visiting the conversions of params collection elements? This could be added to test plan and/or in a future PR. #Resolved

@@ -1006,14 +1006,12 @@ private void ReferToTempIfReferenceTypeReceiver(BoundLocal receiverTemp, ref Bou
BoundExpression? optimized;

Debug.Assert(expanded ? rewrittenArguments.Length == parameters.Length : rewrittenArguments.Length >= parameters.Length);
Debug.Assert(rewrittenArguments.Count(a => a.IsParamsArray) == (expanded ? 1 : 0));
Debug.Assert(rewrittenArguments.Count(a => a.IsParamsCollection) <= (expanded ? 1 : 0));
Copy link
Contributor

@RikkiGibson RikkiGibson Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: it looks like in the params-collections (non-array) case, the IsParamsCollection flag is lost after the collection is lowered. Hence relaxing the assert here. #Resolved

@@ -495,6 +495,18 @@ internal bool ConversionHasSideEffects()

return true;
}

public new bool IsParamsCollection
Copy link
Contributor

@RikkiGibson RikkiGibson Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: containing type is BoundConversion here #Resolved

@AlekseyTs
Copy link
Contributor Author

@333fred, @dotnet/roslyn-compiler For the second review.

@AlekseyTs
Copy link
Contributor Author

@333fred, @dotnet/roslyn-compiler For the second review.

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of small things that are fine for a followup. Otherwise, LGTM

@AlekseyTs AlekseyTs merged commit 569dcb7 into dotnet:features/ParamsCollections Dec 11, 2023
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - ParamsCollections untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants