Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Mistakenly using a Dynamicparam block in single-body functions fails obscurely #6431

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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

Function foo {
    [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)
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.The issue is fixed.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.