Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify Operator Precedence #261

Open
tadbyt opened this issue Jan 30, 2024 · 0 comments
Open

Clarify Operator Precedence #261

tadbyt opened this issue Jan 30, 2024 · 0 comments

Comments

@tadbyt
Copy link
Contributor

tadbyt commented Jan 30, 2024

Location

https://developer.apple.com/documentation/swift/operator-declarations
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/advancedoperators#Compound-Assignment-Operators
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/advancedoperators#Precedence-for-Custom-Infix-Operators
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations#Precedence-Group-Declaration

Description

The set of precedence groups listed in the Operator Declarations article, referenced from multiple locations in The Swift Programming Language, includes an AssignmentPrecedenceGroup that is the lowest level. It is unclear whether the operator precedence of a custom compound assignment operator is implicitly associated with this precedence level or its precedence level must be explicitly specified.

Secondly, it is unclear whether a new precedence group may be created with a lower precedence than the **AssignmentPrecedenceGroup"". It likely shouldn't be allowed as that would prevent such an operator from being executed unless it were contained in a parenthesized expression.

In either event, the behavior of Swift should be clarified in the document.

Correction

In either the Compound Assignment Operators or Precedence for Custom Infix Operators subsection of the Advanced Operators section, add whichever of the following is correct:

Custom compound assignment operators are implicitly assigned to the AssignmentPrecedenceGroup precedence group.

or

As with other custom infix operators, custom compound assignment operators must be explicitly assigned to a precedence group. In general, these should be assigned to the AssignmentPrecedenceGroup precedence group.

In the Precedence Group Declaration subsection of the Declarations section, add the whichever of following notes is correct below the existing note:

Note: Custom precedence groups may not be assigned a precedence below the AssignmentPrecedenceGroup precedence group.

or

Note: Custom precedence groups should not be assigned a precedence below the AssignmentPrecedenceGroup precedence group. To do so would require that those operators be enclosed in a parenthesized expression in order for their value to be employed in an assignment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant