Get concrete bounds of TypeRepr #22438
Unanswered
s5bug
asked this question in
Metaprogramming
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After my success with https://scastie.scala-lang.org/O4YhUozxSnO2PdXGKwivwQ, I want to create a macro which automatically rejects cases where the
match
would be non-exhaustive.For
A =:!= B
, this means getting a concreteAL
andAU
s.t.A >: AL <: AU
, and likewise forB
. How do I do this? I don't see any method to grabTypeBounds
off of aTypeRepr
. I currently haveConsider the case where someone writes
This should fail, as
T = String
is a valid possibility. However,should succeed, as
CharSequence
is never going to be widenable toT
.It's impossible to implement this with just subtype checks on
T
. Considerfoo[CharSequence]
:This
false, false
result, 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
,BU
are all concrete. (ex. a generic with no bounds, i.e.def foo[A]
, would haveAL = Nothing
andAU = Any
.) AnA <:!< B
should be legal iff:BU <:< AL
and!(AL =:= BU)
(widening to the upper bound ofB
would not enter the lower bound ofA
), orProvablyDisjoint[A, B]
Otherwise,
A
andB
are possibly not disjoint, and if one is joint with the other, they share at least one type of overlapFor an
A =:!= B
to be legal:BU <:< AL
and!(AL =:= BU)
(A <:!< B
), orAU <:< BL
and!(BL =:= AU)
(B <:!< A
), orProvablyDisjoint[A, B]
I think
ProvablyDisjoint
is 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