-
Notifications
You must be signed in to change notification settings - Fork 205
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
[patterns] Constant context? #2758
Comments
It's slightly tricky, because there are contexts that look like they must be Will users be more or less confused if we allow the Are users going to be more or less confused by making some positions implicitly const, and others not. That requires us to commit to such parameters always being const, which means we can't do: case List(length: var length & >= 2, last: var ultimate, [length - 2]: var penultimate) where the (I want to generalize object-pattern accessors to not just be getters, so we could also end up with |
I agree. I could see us loosening the restriction on relational pattern operands to allow non-const ones which would be a breaking change if we make it an implicit const context. In practice, I think almost all relational operand RHS expressions will be either integer literals or named constants, neither of which require |
- Allow object pattern fields to tear off methods. - No exception for non-exhaustive switch statements that don't need to be exhaustive. - Promoted types and bounds can be always-exhaustive. - Fix incorrect static error with cast patterns in assignments. - Clarify that patterns are not const contexts. Fix #2561. Fix #2698. Fix #2765. Fix #2758.
* [patterns] Fix a handful of small-ish patterns issues: - Allow object pattern fields to tear off methods. - No exception for non-exhaustive switch statements that don't need to be exhaustive. - Promoted types and bounds can be always-exhaustive. - Fix incorrect static error with cast patterns in assignments. - Clarify that patterns are not const contexts. Fix #2561. Fix #2698. Fix #2765. Fix #2758. * Tweak wording in a few places.
Thanks to @sgrekhov for bringing up this issue. It would seem convenient and benign if syntactic positions in patterns that require a constant expression could be a constant context (that is:
const
can be left implicit). For example:This could apply to at least three constructs:
<bitwiseOrExpression>
of a<relationalPattern>
.<expression>
of a<constantPattern>
of the form'const' '(' <expression> ')'
.<elements>
of a collection pattern ('const' '[' <elements>? ']'
, or'const' '{' <elements>? '}'
).@munificent, @kallentu, @stereotype441, @jakemac53, @lrhn, @leafpetersen, @natebosch, WDYT?
The text was updated successfully, but these errors were encountered: