-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Precedence diagram is missing partial
operator
#5010
Comments
Suggestion: for the time being, we take a restrictive stance, but are open to design changes in this area:
Allowing This seems the direction that is most in line with the design described in #777. |
Just a note in support of writing "const partial C", being able to have a helper |
That wouldn't need The |
Description of the bug:
The precedence diagram is missing the
partial
operator, and there are multiple choices for what should be added.const
(non-associative): disallowsconst partial C
,partial const C
, andpartial partial C
.const
(either associative or non-associative): allowsconst partial C
, disallowspartial const C
.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.htmlDocumentation of
partial
: https://docs.carbon-lang.dev/docs/design/classes.html#partial-class-typeWhat should it say instead?
Two options seem reasonable here. Option 1:
const
andpartial
are in the same precedence group, which is non-associative.Rationale: while the operations performed by
const
andpartial
probably[*] commute, it would be surprising to apply both to the same type (much likeconst 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 aboveconst
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 ofconst
andpartial
is rejected unless parenthesized.Rationale:
partial
applies more "directly" to the type thanconst
does, becausepartial
applies only to classes whereasconst
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 applypartial
to a typeconst C
at all, such as in the expressionpartial (const C)
, or in a generic wherepartial T
may be applied to aT
that evaluates toconst C
. In particular, it's not obvious whetherconst C
is a class type, or is close enough to being a class type, forpartial
to apply.Additionally, it's not clear whether
partial (partial C)
should be valid and should decay topartial C
(likeconst
), or whether it should be invalid becausepartial C
is not a class type. The design says:... and even if
partial C
orconst C
is considered to be a class type, it's not clear whether it's abase
orabstract
class.The text was updated successfully, but these errors were encountered: