Skip to content

Incorrect operator precedence #13331

Open

Description

@sharpchen

Type of issue

Typo

Feedback

  1. Null coalescing operator should have higher precedence than comparison operator

Source: https://github.com/PowerShell/PowerShell/blob/b58ff3b8eae8d8a2ea25f510535dc3ce86589bb9/src/System.Management.Automation/engine/parser/token.cs#L620-L630

2 -le $null ?? 10 # True
(2 -le $null) ?? 10 # False
  1. -bnot should have same precedence as -not
  2. -not should have higher precedence than binary ,
-not 1, 2 # False, 2
-bnot 1, 2 # -2, 2
  1. -bnot has higher precedence than + and -
-bnot 1 - 1 # -3
-bnot (1 - 1) # -1

Just some examples I found, I'm writing a PowerShell grammar so this is really a pain for me.

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operator_precedence?view=powershell-7.6#long-description

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.6/Microsoft.PowerShell.Core/About/about_Operator_Precedence.md

Author

Sean Wheeler (@sdwheeler)

Platform Id

eefdbf75-8340-dd2a-37df-dd6198415dfb

Document Id

0c0f2a79-010a-ae68-378f-baa440c6023d

Activity

  1. changed the title [-]Null coalescing operator should have higher precedence than comparison operator[/-] [+]Incorrect operator precedence[/+] on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions