Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

The "Introduce parameter" refactoring generated duplicate parameter names when the inferred name conflicted with existing parameters, causing CS0100 and CS0229 compiler errors.

Changes

  • Modified GetNewParameterNameAsync in IntroduceParameterDocumentRewriter.cs to use ISemanticFactsService.GenerateUniqueName, ensuring generated parameter names don't conflict with existing parameters by appending numerical suffixes when needed

  • Added test coverage for all three code action variants (direct refactoring, trampoline, overload) and edge cases including multiple conflicts

Example

Before:

int M(int v) => v + 1;  // Select "v + 1" → Introduce parameter
// Generated: int M(int v, int v) { }  // CS0100: duplicate parameter

After:

// Generated: int M(int v, int v1) { }
Original prompt

This section details on the original issue you should resolve

<issue_title>"Introduce parameter" may generate duplicate/ambiguous parameters</issue_title>
<issue_description>Version Used: VS 26 Insiders [11218.70]

Steps to Reproduce:
Select the marked range, open the lightbulb menu and "Introduce parameter for v+1" -> "into new overload"

class C
{
    int M(int v)
    {
        return $v + 1$;
    }
}

Expected Behavior:
The new parameter name is unambiguous and not a duplicate, e.g. by adding a numerical suffix, like v1.

Actual Behavior:
The new parameter has the same name as the existing parameter, leading to conflicts:

int M(int v, int v) // CS0100: The parameter name 'v' is a duplicate
{
    return v; // CS0229: Ambiguity between 'int v' and 'int v'
}

All three options for "Introduce parameter" have this issue in some way.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with ambiguous parameter names in overloads Fix duplicate parameter names in introduce parameter refactoring Nov 21, 2025
Copilot AI requested a review from CyrusNajmabadi November 21, 2025 19:55
Copilot finished work on behalf of CyrusNajmabadi November 21, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Introduce parameter" may generate duplicate/ambiguous parameters

2 participants