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

ParameterSet Binding Error in PS5.0+ #2212

Open
Jaykul opened this issue Sep 8, 2016 · 5 comments
Open

ParameterSet Binding Error in PS5.0+ #2212

Jaykul opened this issue Sep 8, 2016 · 5 comments
Labels
Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Engine core PowerShell engine, interpreter, and runtime

Comments

@Jaykul
Copy link
Contributor

Jaykul commented Sep 8, 2016

When binding with multiple parameter sets, the binder confuses position and sets the wrong value on the parameter.

This bug exists since at least PS 4

Steps to reproduce

function Test-Parameter {
    [CmdletBinding()]
    param
    (
        [Parameter(ParameterSetName = 'Two', Position = 0)]
        [Parameter(ParameterSetName = 'One', Position = 1)]
        [string]
        $First,

        [Parameter(ParameterSetName = 'Two', Position = 1)]
        [string]
        $Second
    )

    "ParameterSet " + $PSCmdlet.ParameterSetName
    $PSBoundParameters
}

Test-Parameter Hello World

Expected behavior

The expected output is:

ParameterSet Two

Key    Value
---    -----
First  Hello
Second  World

Actual behavior

The $First parameter is incorrectly bound to the same value as the $Second parameter:

ParameterSet Two

Key    Value
---    -----
First  World
Second World

Environment data

This happens on PowerShell 4, 5, and 6.0.0-alpha.9

Experimental Notes

The bug is caused by having the Position index of the first parameter in the non-matched parameter set be the same as the Position index of the second parameter in the matched parameter set.

That is, if you change [Parameter(ParameterSetName = 'One', Position = 1)] to [Parameter(ParameterSetName = 'One', Position = 0)] it is does not occur

And if you change [Parameter(ParameterSetName = 'Two', Position = 1)] to [Parameter(ParameterSetName = 'Two', Position = 10)] it does not occur

But if you change them both to, say, Position = 5 then it does occur. Even if there are other parameters and other parameter sets.

And of course, if you specify the parameter name when you call it, or if the parameters are of different types, then this does not occur.

@SteveL-MSFT SteveL-MSFT added the WG-Engine core PowerShell engine, interpreter, and runtime label Sep 8, 2016
@daxian-dbw daxian-dbw self-assigned this Sep 16, 2016
@joeyaiello
Copy link
Contributor

@daxian-dbw can you please unassign yourself from this unless you're actively working on it?

@SteveL-MSFT SteveL-MSFT added the Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors label Nov 2, 2016
@daxian-dbw
Copy link
Member

I planed to investigate and work on it, though haven't got to it yet.

@daxian-dbw daxian-dbw removed their assignment Nov 3, 2016
@Jaykul
Copy link
Contributor Author

Jaykul commented May 16, 2023

I recognize that this probably feels like something you meant to do, at this point, but can't we please fix this, or at least make it error or warn that things have gone badly wrong?

@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 16, 2023
@Jaykul
Copy link
Contributor Author

Jaykul commented Nov 17, 2023

How can we just ignore this?
It still happens in 7.4

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 17, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label May 15, 2024
@powercode
Copy link
Collaborator

Bump

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Resolution-No Activity Issue has had no activity for 6 months or more label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Up-for-Grabs Up-for-grabs issues are not high priorities, and may be opportunities for external contributors WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

5 participants