-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Refutable extractor may be an Apply tree #15651
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.
Let's avoid MatchErrors outright, by using the recursive funPart, and falling back if it's not a select.
fn match | ||
case Select(id, _) => id | ||
case Apply(Select(id, _), _) => id | ||
case TypeApply(Select(id, _), _) => id | ||
em"pattern binding uses refutable extractor `$extractor`" |
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.
fn match | |
case Select(id, _) => id | |
case Apply(Select(id, _), _) => id | |
case TypeApply(Select(id, _), _) => id | |
em"pattern binding uses refutable extractor `$extractor`" | |
tpd.funPart(fn) match | |
case Select(id, _) => id | |
case _ => "" | |
if extractor == "" | |
em"pattern binding uses refutable extractor" | |
else | |
em"pattern binding uses refutable extractor `$extractor`" |
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.
oooh, was unaware of funPart
, very nice, thanks!
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.
extracting the extractor name needs to deal with arbitrary parameter lists (and type parameter lists for future proofing), for example it still crashes if I add another using clause:
class Rational
import scala.quoted.*
class TC
object meta:
object rationalTE:
def unapply(using Quotes)(using TC)(tr: quotes.reflect.TypeRepr): Option[Rational] = ???
def foo(using Quotes)(using TC)(p: quotes.reflect.TypeRepr): Unit =
val rationalTE(e) = p // warn: pattern binding uses refutable extractor `meta.rationalTE`
Yeah, using TreeInfo's funPart will address that. |
And in fact we need to be able to handle arbitrary parameter lists (and type parameter lists) when extracting the extractor name. Fixes scala#15650
Rebased with suggested changes and an additional test case. |
Fixes #15650