Title: Enable simple detection of [AutomationNull]::Value with -is [AutomationNull] · Issue #13465 · PowerShell/PowerShell · GitHub
Open Graph Title: Enable simple detection of [AutomationNull]::Value with -is [AutomationNull] · Issue #13465 · PowerShell/PowerShell
X Title: Enable simple detection of [AutomationNull]::Value with -is [AutomationNull] · Issue #13465 · PowerShell/PowerShell
Description: Follow-up from #9997, which lacked a clear proposal. Related to #11921 (-is [pscustomobject]) and #10704 (-is $null) Summary of the new feature/enhancement Enable the following -is test to allow for a PowerShell-idiomatic detection of th...
Open Graph Description: Follow-up from #9997, which lacked a clear proposal. Related to #11921 (-is [pscustomobject]) and #10704 (-is $null) Summary of the new feature/enhancement Enable the following -is test to allow fo...
X Description: Follow-up from #9997, which lacked a clear proposal. Related to #11921 (-is [pscustomobject]) and #10704 (-is $null) Summary of the new feature/enhancement Enable the following -is test to allow fo...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/13465
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enable simple detection of [AutomationNull]::Value with -is [AutomationNull]","articleBody":"* Follow-up from #9997, which lacked a clear proposal.\r\n* Related to #11921 (`-is [pscustomobject]`) and #10704 (`-is $null`)\r\n\r\n## Summary of the new feature/enhancement\r\n\r\nEnable the following `-is` test to allow for a PowerShell-idiomatic detection of the `[System.Management.Automation.Internal.AutomationNull]::Value` value that commands that output \"nothing\" technically output.\r\n\r\n```powershell\r\n# `\u0026 {}` outputs \"nothing\", which is technically [System.Management.Automation.Internal.AutomationNull]::Value\r\nPS\u003e \u0026 {} -is [AutomationNull] # WISHFUL THINKING\r\nTrue\r\n```\r\n\r\nIn _expression_ contexts `[System.Management.Automation.Internal.AutomationNull]::Value` is treated like `$null`, but there are **contexts where the distinction matters**:\r\n\r\nIn the **pipeline**:\r\n\r\n```powershell\r\n# A true $null is sent through the pipeline. \r\nPS\u003e $null | % { 'here' }\r\nhere\r\n\r\n# [System.Management.Automation.Internal.AutomationNull]::Value is NOT sent through the pipeline\r\n# - it is an empty enumeration.\r\nPS\u003e \u0026 { } | % { 'here' }\r\n# NO output\r\n```\r\n\r\nAlso, because the **`switch` statement** treats its operand as an _enumeration_, a `[System.Management.Automation.Internal.AutomationNull]::Value` value causes the statement to be skipped altogether; that is, it is effectively _ignored_:\r\n\r\n``` powershell\r\n$val = \u0026 {}\r\n# Because $val contains [System.Management.Automation.Internal.AutomationNull]::Value,\r\n# the switch statement is effectively ignored;\r\nswitch ($val) {\r\n default { 'hi' }\r\n}\r\n```\r\n\r\n**Operators** behave inconsistently with AutomationNull as the LHS (see #3866):\r\n\r\n```powershell\r\nPS\u003e [System.Management.Automation.Internal.AutomationNull]::Value -match 'foo'\r\n# NO OUTPUT - LHS was interpreted as *collection*\r\n\r\nPS\u003e [System.Management.Automation.Internal.AutomationNull]::Value -eq 'foo'\r\nFalse # LHS was interpreted as a *scalar*\r\n```\r\n\r\nIn short: **Because `[System.Management.Automation.Internal.AutomationNull]::Value` causes observable differences in behavior from `$null`, it must be discoverable.**\r\n\r\n\r\n## Proposed technical implementation details (optional)\r\n\r\nNote: Strictly speaking, `[System.Management.Automation.Internal.AutomationNull]::Value` is of type `[System.Management.Automation.PSObject]`, but treating it as an instance of `AutomationNull` would be a helpful \"white lie\", similar to the one `-is` already tells when it reports a `[psobject]` wrapper's `.BaseObject` value's type as the type.\r\n\r\nHowever, @SeeminglyScience's [proposed implementation here](https://github.com/PowerShell/PowerShell/issues/9997#issuecomment-580743572) would actually resolve this issue, via a new, _public_ `System.Management.Automation.AutomationNull` wrapper, for which an `[AutomationNull]` _type accelerator_ would have to be defined.\r\n\r\n\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2020-08-17T20:18:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/13465/PowerShell/issues/13465"}
| 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:6118d579-170e-7e25-2032-3b9cdffbf1a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9706:8F1AE:84F14C:88BFB7:6A59F054 |
| html-safe-nonce | 1b6b6cfe1bfc94c6b69c94b5de2c9397991cfb3a1539f97856232b9599fd7bda |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzA2OjhGMUFFOjg0RjE0Qzo4OEJGQjc6NkE1OUYwNTQiLCJ2aXNpdG9yX2lkIjoiNjA4MTY4ODc4NDMxNDAwMDIwIiwicmVnaW9uX2VkZ2UiOiJzZWEiLCJyZWdpb25fcmVuZGVyIjoic2VhIn0= |
| visitor-hmac | 426bfc09cc2767b2500749f0b9624fd49ffff34a7fc4bb8b41033ee2984fb92f |
| hovercard-subject-tag | issue:680500677 |
| 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/13465/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2c6a755f09eaba8d70c747b3c5d1c352a819d6b3067745442b575e002eae1844/PowerShell/PowerShell/issues/13465 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2c6a755f09eaba8d70c747b3c5d1c352a819d6b3067745442b575e002eae1844/PowerShell/PowerShell/issues/13465 |
| og:image:alt | Follow-up from #9997, which lacked a clear proposal. Related to #11921 (-is [pscustomobject]) and #10704 (-is $null) Summary of the new feature/enhancement Enable the following -is test to allow fo... |
| 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 | ba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353 |
| 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 | 24801cf86623a319252348d1fd69122ad974b842 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width