You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function call foo should succeed, and string 'OK' should be output.
Actual behavior
The .GetNewClosure() call fails with the following error message:
Exception calling "GetNewClosure" with "0" argument(s): "The attribute cannot be added because variable bar with value would no longer be valid."
That is, an attempt is made to include the unbound-bar parameter value - the $bar variable - in the closure, which apparently then defaults to $null, which violates its validation attribute.
Passing a valid -bar value makes the problem go away; e.g., foo -bar ''.
I suspect this is a bug: If the function itself treats $bar in the absence of a -bar parameter value as nonexistent, so should .GetNewClosure().
An example of how the problem might affect a real-world scenario can be found here.
Environment data
PowerShell v6.0.0-alpha (v6.0.0-alpha.15) on Darwin Kernel Version 16.4.0: Thu Dec 2222:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64
PowerShell v5.1.14393.693 on Microsoft Windows 10 Pro (64-bit; v10.0.14393)