carbon-lang
carbon-lang copied to clipboard
Precedence diagram is missing `partial` operator
Description of the bug:
The precedence diagram is missing the partial operator, and there are multiple choices for what should be added.
- Same precedence group as
const(non-associative): disallowsconst partial C,partial const C, andpartial partial C. - Precedence group above
const(either associative or non-associative): allowsconst partial C, disallowspartial const C. - Precedence group below
const(either associative or non-associative): allowspartial const C, disallowsconst partial C.
Link to documentation:
Diagram: https://docs.carbon-lang.dev/docs/design/expressions/#precedence
Proposal #777, which added partial: https://docs.carbon-lang.dev/proposals/p0777.html
Documentation of partial: https://docs.carbon-lang.dev/docs/design/classes.html#partial-class-type
What should it say instead?
Two options seem reasonable here. Option 1:
const and partial are in the same precedence group, which is non-associative.
Rationale: while the operations performed by const and partial probably[*] commute, it would be surprising to apply both to the same type (much like const const T is surprising) and so rejecting may be preferable to accepting. However, this rule might be more of an "HOA rule" than a "building code".
Option 2:
partial is in a precedence group above const in the diagram -- that is, partial has higher precedence. Both are non-associative. const partial C is accepted, all other combinations with more than one of const and partial is rejected unless parenthesized.
Rationale: partial applies more "directly" to the type than const does, because partial applies only to classes whereas const is a general type operator. So if both can be applied in the same expression, partial should be applied to the type first.
Any other information, logs, or outputs that you want to share?
[*]: For a class type C, it's unclear whether it should be valid to apply partial to a type const C at all, such as in the expression partial (const C), or in a generic where partial T may be applied to a T that evaluates to const C. In particular, it's not obvious whether const C is a class type, or is close enough to being a class type, for partial to apply.
Additionally, it's not clear whether partial (partial C) should be valid and should decay to partial C (like const), or whether it should be invalid because partial C is not a class type. The design says:
The keyword
partialis only valid for abaseorabstractclass. For final classes, there is no need for a second type.
... and even if partial C or const C is considered to be a class type, it's not clear whether it's a base or abstract class.