加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scala 2.11类型方差更改

发布时间:2020-12-16 09:49:38 所属栏目:安全 来源:网络整理
导读:在 Scala 2.10.4中,这编译: trait Foo[-U,T]{ type Contra = U} 但是在2.11.0中同样失败了: contravariant type U occurs in invariant position in type U of type Contra trait Foo[-U,T] {type Contra = U} 有可用的解决方法吗?尝试将Scala库移植到2.1
在 Scala 2.10.4中,这编译:

trait Foo[-U,T]{
  type Contra = U
}

但是在2.11.0中同样失败了:

contravariant type U occurs in invariant position in type U of type
Contra trait Foo[-U,T] {type Contra = U}

有可用的解决方法吗?尝试将Scala库移植到2.11并且需要逆变类型以获得编译器拾取的大量隐式defs(即,使U不变量似乎不是一种选择).

谢谢

解决方法

我无法想象有可用的工作.我说这个的原因是支持路径依赖类型:

def foo[T <: Foo[A,B]](that: T): that.Contra

这将Contra类型置于错误的位置.作为操作的结果,您不能返回逆变类型.也许搜索和验证这些工作需要做很多工作,编译器的作者认为这个小角落案例造成了太多的负担,或者是你发现的编译器错误.

顺便说一句,这只是我的疯狂猜测.我必须阅读编译器代码以确定哪种方式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读