Scala3匹配类型和F-Bounded类型:“无法证明”

鉴于:

abstract class Quantity[A <: Quantity[A]]
sealed trait UnitOfMeasure[A]

class Time extends Quantity[Time]
object Minutes extends UnitOfMeasure[Time]

class PowerRamp extends Quantity[PowerRamp]
object KilowattsPerHour extends UnitOfMeasure[PowerRamp]
  
type Test[X <: UnitOfMeasure[?]] = X match
  case UnitOfMeasure[t] => t

编译如下:

summon[Test[Minutes.type] =:= Time]
summon[Test[KilowattsPerHour.type] =:= PowerRamp]

但是,如果UnitOfMeasure声明了trait :

sealed trait UnitOfMeasure[A <: Quantity[A]]

两次传票都失败:

Cannot prove that Test[Minutes.type] =:= Time.

Note: a match type could not be fully reduced:
  trying to reduce Test[Minutes.type]
  failed since selector Minutes.type
  matches none of the cases
    case UnitOfMeasure[t] => t

我究竟做错了什么?

斯卡斯蒂链接

以上是Scala3匹配类型和F-Bounded类型:“无法证明”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>