Skip to content

Convert to local function: ensure unique names for multiple discard parameters#83644

Merged
akhera99 merged 1 commit into
dotnet:mainfrom
reacheight:convert-to-local-func-with-multiple-discards
May 22, 2026
Merged

Convert to local function: ensure unique names for multiple discard parameters#83644
akhera99 merged 1 commit into
dotnet:mainfrom
reacheight:convert-to-local-func-with-multiple-discards

Conversation

@reacheight
Copy link
Copy Markdown
Contributor

@reacheight reacheight commented May 11, 2026

Fixes #83144

Microsoft Reviewers: Open in CodeFlow

@reacheight reacheight requested a review from a team as a code owner May 11, 2026 15:43
@dotnet-policy-service dotnet-policy-service Bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels May 11, 2026

if (multipleDiscardParameters && IsDiscardParameter(parameterNode))
{
var newName = generator.Identifier($"_{discardParameterIndex++}");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried using NameGenerator.EnsureUniqueness instead of explicitly generating names, but IMO it got pretty complicated when trying to avoid doing unnecessary work, so I stuck with this approach.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what got complicated? NameGenerator.EnsureUniqueness is def the righ way to go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it just looked to me that the code got unnecessary harder to read, but I will give it another shot, thanks

Copy link
Copy Markdown
Contributor

@CyrusNajmabadi CyrusNajmabadi May 12, 2026

Choose a reason for hiding this comment

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

Yes, i'd def like to see with NameGenerator.EnsureUniqueness, since it was defined for cases like these. Thanks :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I rewrote this using NameGenerator to ensure unique names in general, not just for multiple discard parameters, which fixes more (non-compiling) cases. But let me know if this feels like overkill and I should revert to multiple discards case only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer this to be scoped to just multiple discard parameters -- not sure I'd expect that behavior for a case like Func<int, int, int> x = (a, a) => 1;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@akhera99 Thanks, reverted to this case only

@reacheight reacheight marked this pull request as draft May 11, 2026 16:48
@reacheight reacheight force-pushed the convert-to-local-func-with-multiple-discards branch 2 times, most recently from f207505 to a9f2d39 Compare May 13, 2026 19:43
@reacheight reacheight changed the title Convert to local function: ensure unique names for multiple discard parameters Convert to local function: ensure unique names for function parameters May 13, 2026
@reacheight reacheight marked this pull request as ready for review May 13, 2026 19:50
@reacheight reacheight force-pushed the convert-to-local-func-with-multiple-discards branch from a9f2d39 to 2f9098c Compare May 14, 2026 17:39
@akhera99
Copy link
Copy Markdown
Member

/azp run roslyn-CI

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@reacheight reacheight force-pushed the convert-to-local-func-with-multiple-discards branch from 2f9098c to 98140ee Compare May 22, 2026 18:01
@reacheight reacheight changed the title Convert to local function: ensure unique names for function parameters Convert to local function: ensure unique names for multiple discard parameters May 22, 2026
@reacheight reacheight force-pushed the convert-to-local-func-with-multiple-discards branch from 98140ee to e66a1a0 Compare May 22, 2026 18:02
@akhera99
Copy link
Copy Markdown
Member

Looks good, thank you for your contribution!

@akhera99 akhera99 merged commit bbeb47c into dotnet:main May 22, 2026
25 checks passed
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'Convert to local function' fix produces compiler error when at least 2 initial parameters are discards

3 participants