在类型成员中作为参数提及的协变类型参数

时间:2018-10-09 14:34:43

标签: scala generics

trait Element[+A] {
  type T = A
}
// Error: covariant type A occurs in invariant 
// position in type A of type T type T = A

为什么不允许在类型成员中使用协变类型参数?

此问题有一个answer,但说明未涵盖问题“为什么”足够好。如果有一些示例可以在运行时中断类型系统,那将是很好的。

编辑:

我发现这种限制存在很长的历史:

SI-6566(和this)-非私有类型别名必须不变

SI-7093-受保护的[this]方差转义阴影不正确

0 个答案:

没有答案
相关问题