Skip to content

Use tuple or boolean types for extractors that will always match #10738

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

Conversation

nicolasstucki
Copy link
Contributor

For these, it is the TypeTest that determines if the match will succeed.

Constant do not follow this design and hence keep Option

@nicolasstucki nicolasstucki marked this pull request as ready for review December 10, 2020 10:08
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -156,7 +156,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
withDefaultPos(tpd.Import(expr, selectors))
def copy(original: Tree)(expr: Term, selectors: List[Selector]): Import =
tpd.cpy.Import(original)(expr, selectors)
def unapply(tree: Import): Option[(Term, List[Selector])] =
def unapply(tree: Import): Some[(Term, List[Selector])] =
Some((tree.expr, tree.selectors))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type can be just (Term, List[Selector]), it is also irrefutable -- product matches are always irrefutable. The same for the other changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just investigating that possibility :)
I will update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also caught some extra bugs

For these, it is the `TypeTest` that determines if the match will succeed.
@nicolasstucki nicolasstucki force-pushed the use-precise-return-types-for-unapplies branch from 1e386ab to 90ac3cb Compare December 10, 2020 11:01
@nicolasstucki nicolasstucki changed the title Use Some for extractors that will always match Use tuple or boolean types for extractors that will always match Dec 10, 2020
@nicolasstucki nicolasstucki merged commit cb49fa1 into scala:master Dec 10, 2020
@nicolasstucki nicolasstucki deleted the use-precise-return-types-for-unapplies branch December 10, 2020 12:46
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

4 participants