-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use tuple or boolean types for extractors that will always match #10738
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.
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)) |
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 return type can be just (Term, List[Selector])
, it is also irrefutable -- product matches are always irrefutable. The same for the other changes.
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.
I was just investigating that possibility :)
I will update it.
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.
This also caught some extra bugs
For these, it is the `TypeTest` that determines if the match will succeed.
1e386ab
to
90ac3cb
Compare
Some
for extractors that will always match
For these, it is the
TypeTest
that determines if the match will succeed.Constant
do not follow this design and hence keepOption