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

Same param specified twice discards parameter variable attributes #3301

Closed
mklement0 opened this issue Mar 10, 2017 · 6 comments
Closed

Same param specified twice discards parameter variable attributes #3301

mklement0 opened this issue Mar 10, 2017 · 6 comments
Labels
Resolution-No Activity Issue has had no activity for 6 months or more WG-Engine core PowerShell engine, interpreter, and runtime

Comments

@mklement0
Copy link
Contributor

mklement0 commented Mar 10, 2017

Steps to reproduce

Create script ./script.ps1 as follows:

param([ValidateSet('bar', 'baz')] [string] $Foo)

# Output count of attributes.
(Get-Variable Foo).Attributes.Count

Then dot-source the script twice:

> . ./script.ps1; . ./script.ps1

Expected behavior

3
3

Actual behavior

3
0

Repeated dot-sourcing happens implicitly when you run your code repeatedly in the ISE, for instance.

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.16) on Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64
@SteveL-MSFT
Copy link
Member

Don't have to dot-source

PS /home/steve> param([ValidateSet('bar', 'baz')] [string] $Foo)                            
PS /home/steve>                                                                             
PS /home/steve> # Output count of attributes.                                               
PS /home/steve> (Get-Variable Foo).Attributes.Count                                         
3
PS /home/steve> param([ValidateSet('bar', 'baz')] [string] $Foo)                            
PS /home/steve>                                                                             
PS /home/steve> # Output count of attributes.                                               
PS /home/steve> (Get-Variable Foo).Attributes.Count                                         
0

@SteveL-MSFT SteveL-MSFT added the WG-Engine core PowerShell engine, interpreter, and runtime label Mar 10, 2017
@SteveL-MSFT SteveL-MSFT changed the title Repeated dot-sourcing of a script quietly discards parameter variable attributes same param specified twice discards parameter variable attributes Mar 10, 2017
@SteveL-MSFT SteveL-MSFT changed the title same param specified twice discards parameter variable attributes Same param specified twice discards parameter variable attributes Mar 10, 2017
@lzybkr
Copy link
Member

lzybkr commented Apr 19, 2018

@SteveL-MSFT - the interactive prompt is equivalent to dot sourcing. Dot sourcing just means - don't create a new scope. The interactive prompt executes everything in global scope which also means no new scope is created.

@SteveL-MSFT SteveL-MSFT added this to the 6.2.0-Consider milestone Apr 19, 2018
@SteveL-MSFT SteveL-MSFT modified the milestones: 6.2.0-Consider, Future Jun 21, 2018
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

1 similar comment
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

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

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-No Activity Issue has had no activity for 6 months or more WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

3 participants