鉴于:
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
:
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
我做错了什么?