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

Fix #2578: (part 2) Make for-generators filter only if prefixed with case. #6448

Merged
merged 14 commits into from
May 15, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 4, 2019

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.

Copy link
Member

@dottybot dottybot left a 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:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Add" instead of "Added")
  7. Wrap the body at 80 characters
  8. 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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`.
Copy link
Contributor

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?

Suggested change
/** 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.

@abgruszecki abgruszecki assigned odersky and unassigned abgruszecki May 13, 2019
odersky added 13 commits May 15, 2019 11:34
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.
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

Successfully merging this pull request may close these issues.

6 participants