2

给定

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

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

这编译(这里没有惊喜):

summon [Neg [True] =:= False]

但是,令人惊讶的是,这不会:

summon [Neg [False] =:= True]

它似乎取决于类型匹配中的案例顺序 - 如果我更改分支的顺序NegNeg [False]将起作用,但Neg [True]不会?!

斯卡拉 3.0.0-RC3

编辑:

这按预期工作(Neg不变):

trait Bool
class True extends Bool
class False extends Bool

这个也是:

trait Bool
object True extends Bool
object False extends Bool
type True = True.type
type False = False.type
4

0 回答 0