-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix #2578: (part 2) Make for-generators filter only if prefixed with case
.
#6448
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
isIrrefutable(gen.pat, gen.expr) | ||
def needsNoFilter(gen: GenFrom): Boolean = | ||
if (gen.checkMode == GenCheckMode.FilterAlways) // pattern was prefixed by `case` | ||
isIrrefutable(gen.pat, gen.expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a matter of principle, I think that if the user explicitly requested a "filtering binding" by writing case
, then it is less surprising if we always emit a withFilter
call. With zipped
, we've already seen that emitting or not emitting the call can have unobvious consequences on typechecking. I think it'd be for the best if we just let the user decide whether the call is emitted or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll change it.
@@ -925,6 +936,22 @@ object desugar { | |||
} | |||
} | |||
|
|||
/** The selector of a match, which depends of the given `checkMode`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that @unchecked
is also added to irrefutable patterns really confused me until I understood that annotating the selector only affects exhaustivity checks and not irrefutability checks. Perhaps we could note this in the doc?
/** The selector of a match, which depends of the given `checkMode`. | |
/** The selector of a match, which depends of the given `checkMode`. | |
* | |
* The @unchecked annotation is added whenever `checkMode` is not `Exhaustive` to silence | |
* unnecessary inexhaustive match warnings. |
Non-matching members are already removed by the filter.
But wait with this for now, since we can't cross-compile easily otherwise. So currently this is enabled only under -strict.
Add a third mode, Ignore, for generators where the pattern is refutable, but we know it has already been used as a filter in an earlier step.
This was not classified as a pattern binding before, so no filtering was applied.
This is a complement to #6389. Together, they address all aspects of #2578.
The checking part of this is currently only enabled under -strict to allow cross-compilation with Scala 2. As things currently stand, this means it will be made standard in Scala 3.1.