Scala:将特性与“;“相同”;抽象类型成员

Scala:将特性与“;“相同”;抽象类型成员,scala,types,compiler-errors,Scala,Types,Compiler Errors,我一直在关注Java和Scala类型系统上的错误。为了更好地理解这个问题,我一直在尝试解决一个较小的相关问题 我有以下几种: class Parent class Child extends Parent class Grandchild extends Child class GrandGrandchild extends Grandchild 以下是受约束抽象类型的一些特征: trait LowerBound[T] extends{ type M >: T } trait Up

我一直在关注Java和Scala类型系统上的错误。为了更好地理解这个问题,我一直在尝试解决一个较小的相关问题

我有以下几种:

class Parent
class Child extends Parent
class Grandchild extends Child
class GrandGrandchild extends Grandchild
以下是受约束抽象类型的一些特征:

trait LowerBound[T] extends{
  type M >: T
}

trait UpperBound[U] extends{
  type M <: U
}
但我无法定义如下特征:

trait FamilyTreeConstraint extends LowerBound[GrandGrandchild] with UpperBound[Parent]
我得到:

在trait LowerBound中重写类型M,边界>:A$A131.this.grand孙子;
在trait上界中键入M我不知道这种行为的原因,但根据我的经验,如果子类/trait的约束发生变化,通常需要显式重写子类/trait中的
type
定义。我的意思是,一旦在
FamilyTreeConstraint
中明确指定了
M
的限制,编译器就满足了

trait FamilyTreeConstraint extends LowerBound[GrandGrandchild] with UpperBound[Parent] {
  override type M >: Grandchild <: Parent
}
trait FamilyTreeConstraint用上限[Parent]扩展了下限[Grand孙子]{
覆盖类型M>:孙子
trait UpperLower[T,U]{
   type M >: T <: U
}
trait UpperLowerConcrete{
   type M >: GrandGrandchild <: Parent
}
trait FamilyTreeConstraint extends LowerBound[GrandGrandchild] with UpperBound[Parent] {
  override type M >: Grandchild <: Parent
}