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
{{ message }}
Repository navigation
Mistakenly using a Dynamicparam block in single-body functions fails obscurely #6431
This is a minor problem and the behavior is as designed, but perhaps the error message can be improved.
A dynamicparam {} block requires an advanced function's other code to be in begin {}, process{} and end {} blocks.
Instead trying to use dynamicparam in the function's main block alongside top-level code fails obscurely:
Steps to reproduce
Functionfoo {
[CmdletBinding()] param()
DynamicParam {
}
# Placing code here, outside of begin {}, process {} or end {} fails obscurely.'hi'
}
Expected behavior
Actual behavior
At /Users/mklement/Desktop/pg/pg.ps1:33 char:14
+ Function foo {
+ ~
Missing closing '}' in statement block or type definition.
It is not obvious from this error message what the problem is.
Enclosing 'hi' in end { ... } fixes the problem.
Aside from a more helpful error message, perhaps allowing this code is an option (where the top-level code would run in an implied end {} block),
though perhaps that requires special-cased parsing behavior that is not worth the trouble.
Environment data
PowerShell Core v6.0.2 on macOS 10.13.3
PowerShell Core v6.0.2 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.2 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
changed the title [-]Mistakenly using a Dynamicparam block in a single-body functions fails obscurely[/-][+]Mistakenly using a Dynamicparam block in single-body functions fails obscurely[/+]on Mar 19, 2018
Activity
[-]Mistakenly using a Dynamicparam block in a single-body functions fails obscurely[/-][+]Mistakenly using a Dynamicparam block in single-body functions fails obscurely[/+]