8000 Push locals of automatic variables to 'DottedScopes' when dotting script cmdlets by daxian-dbw · Pull Request #4709 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Push locals of automatic variables to 'DottedScopes' when dotting script cmdlets #4709

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

Merged
merged 1 commit into from
Sep 6, 2017

Conversation

daxian-dbw
Copy link
Member

Fix #4688

When dotting a script cmdlet, the locals of automatic variables from the PSScriptCmdlet is not set up in the current scope before parameter binding. The fix is to push the locals in CommandProcessor.OnSetCurrentScope and pop them in CommandProcessor.OnRestorePreviousScope, which will be called from SetCurrentScopeToExecutionScope and RestorePreviousScope respectively.

Summary of changes:

  1. When a new local scope is used, currently we set the locals for CommandProcessor right before parameter binding (in BindCommandLineParametersNoValidation); we set the locals for ScriptCommandProcessor in Prepare. I moved both to the constructor, right after the new scope is created so that the code is more consistent.

  2. In CmdletParameterBinderController.cs, we set up the PSBoundParameters and MyInvocation variables in HandleCommandLineDynamicParameters again, which I think is unnecessary because this method is only called from BindCommandLineParametersNoValidation, where the setup is done for the first time.

  3. Currently, the locals will be set for dotted script cmdlet in EnterScope() and ExitScope(). Now, that logic is moved to OnSetCurrentScope and OnRestorePreviousScope of CommandProcessor. This not only makes sure that locals are set before parameter binding, but also is consistent with the ScriptCommandProcessor.

@daxian-dbw
Copy link
Member Author

@vors Thanks!
@lzybkr can you please take a look when you have time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$PSScriptRoot is not populated when used in a default value for a non-mandatory script parameter
4 participants
0