Fix a casting error when using $PSNativeCommandUsesErrorActionPreference by daxian-dbw · Pull Request #15993 · PowerShell/PowerShell (original) (raw)

Choose a reason for hiding this comment

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

This happens to all powershell action preference variable, and actually, all other automatic variables that don't have the "AllScope" option.

For variables that are not 'AllScope', they are not copied to a new local scope and thus an assignment to the same variable in a nested scope actually create a new variable in that scope, which doesn't have the argument transformation attribute as the one declared in the global scope.

BTW, we want to avoid 'AllScope' variables as much as possible because it's expensive.