Get concrete bounds of TypeRepr #22438
Unanswered
s5bug
asked this question in
Metaprogramming
Replies: 1 comment 3 replies
-
|
type ProbablyDisjoint[A, B] <: Boolean = A match
case B => false
case _ => true(Request with For the other situation, it's hard to even specify what you want. Lower bounds are tricky. But usually they are |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
After my success with https://scastie.scala-lang.org/O4YhUozxSnO2PdXGKwivwQ, I want to create a macro which automatically rejects cases where the
matchwould be non-exhaustive.For
A =:!= B, this means getting a concreteALandAUs.t.A >: AL <: AU, and likewise forB. How do I do this? I don't see any method to grabTypeBoundsoff of aTypeRepr. I currently haveConsider the case where someone writes
This should fail, as
T = Stringis a valid possibility. However,should succeed, as
CharSequenceis never going to be widenable toT.It's impossible to implement this with just subtype checks on
T. Considerfoo[CharSequence]:This
false, falseresult, when summoning the<:!<should fail, is the exact same as a succeeding case:Assume that
type A >: AL <: AU,type B >: BL <: BU, whereAL,AU,BL,BUare all concrete. (ex. a generic with no bounds, i.e.def foo[A], would haveAL = NothingandAU = Any.) AnA <:!< Bshould be legal iff:BU <:< ALand!(AL =:= BU)(widening to the upper bound ofBwould not enter the lower bound ofA), orProvablyDisjoint[A, B]Otherwise,
AandBare possibly not disjoint, and if one is joint with the other, they share at least one type of overlapFor an
A =:!= Bto be legal:BU <:< ALand!(AL =:= BU)(A <:!< B), orAU <:< BLand!(BL =:= AU)(B <:!< A), orProvablyDisjoint[A, B]I think
ProvablyDisjointis easy once I haveAL,AU,BL,BU: I just check that there's no possible subtyping relationships between any of the bounds. However, the difficulty still lies in finding those four types. Is there something in the macro system that will give them to me?Beta Was this translation helpful? Give feedback.
All reactions