2

Given

type Bool
type True <: Bool
type False <: Bool

And

type Neg [B <: Bool] <: Bool =
  B match
    case True => False
    case False => True

This compiles (no surprises here):

summon [Neg [True] =:= False]

But this, surprisingly, does not:

summon [Neg [False] =:= True]

It seems to depend on order of cases in type match - if I change the order of branches in Neg, Neg [False] will work, but Neg [True] won't?!

Scala 3.0.0-RC3

EDIT:

This works as expected (with Neg unchanged):

trait Bool
class True extends Bool
class False extends Bool

This too:

trait Bool
object True extends Bool
object False extends Bool
type True = True.type
type False = False.type
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
Duduk
  • 166
  • 5
  • 2
    This is because `False` could also be `True`, since you only say `<:`. Since the compiler cannot guarantee that a `False` is not a `True`, it just takes the first case every time. See what happens if you make them final classes instead. – user May 03 '21 at 02:17

0 Answers0