Title: Mistakenly using a Dynamicparam block in single-body functions fails obscurely · Issue #6431 · PowerShell/PowerShell · GitHub
Open Graph Title: Mistakenly using a Dynamicparam block in single-body functions fails obscurely · Issue #6431 · PowerShell/PowerShell
X Title: Mistakenly using a Dynamicparam block in single-body functions fails obscurely · Issue #6431 · PowerShell/PowerShell
Description: 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 ...
Open Graph Description: 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...
X Description: 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 {}, pro...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6431
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mistakenly using a Dynamicparam block in single-body functions fails obscurely","articleBody":"This is a minor problem and the behavior is as designed, but perhaps the error message can be improved.\r\n\r\nA `dynamicparam {}` block requires an advanced function's other code to be in `begin {}`, `process{}` and `end {}` blocks.\r\n\r\nInstead trying to use `dynamicparam` in the function's main block _alongside top-level code_ fails obscurely:\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\nFunction foo {\r\n [CmdletBinding()] param()\r\n DynamicParam {\r\n }\r\n\r\n # Placing code here, outside of begin {}, process {} or end {} fails obscurely.\r\n 'hi'\r\n}\r\n\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n\r\n\r\nActual behavior\r\n---------------\r\n\r\n```none\r\nAt /Users/mklement/Desktop/pg/pg.ps1:33 char:14\r\n+ Function foo {\r\n+ ~\r\nMissing closing '}' in statement block or type definition.\r\n```\r\n\r\nIt is not obvious from this error message what the problem is.\r\n\r\nEnclosing `'hi'` in `end { ... }` fixes the problem.\r\n\r\nAside 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), \r\nthough perhaps that requires special-cased parsing behavior that is not worth the trouble.\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell Core v6.0.2 on macOS 10.13.3\r\nPowerShell Core v6.0.2 on Ubuntu 16.04.3 LTS\r\nPowerShell Core v6.0.2 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-03-19T17:28:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/6431/PowerShell/issues/6431"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7e66788e-12de-a64a-e8c3-33482f2cae12 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B512:2BB762:40E7CB5:5BBA73E:6A5501F4 |
| html-safe-nonce | bb348e61e7d068adcac56fd916f0c0869fb612f1660d7c575a08822a7f8075b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTEyOjJCQjc2Mjo0MEU3Q0I1OjVCQkE3M0U6NkE1NTAxRjQiLCJ2aXNpdG9yX2lkIjoiNzk3MzEwNTkzMzQ5MTcwMDIxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2ebe09f741ec4cb515a78a896b1e46c8dd16d3b59e093cd6490f74d6c37102e3 |
| hovercard-subject-tag | issue:306559213 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/6431/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6bd1ec1bff8e2b9656167a0480f53dc959d3f7e3fb144ae66622bec94e373953/PowerShell/PowerShell/issues/6431 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6bd1ec1bff8e2b9656167a0480f53dc959d3f7e3fb144ae66622bec94e373953/PowerShell/PowerShell/issues/6431 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | eae2aab99907699a22d2c8449aa683ca74454fca87211b98f7c7b722086b2839 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6a35ab858be185cd86d12b93a43bccf34e8d8536 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width