为什么Scala编译器在2.10中对自我类型有更严格的要求?
发布时间:2020-12-16 10:03:10 所属栏目:安全 来源:网络整理
导读:我有以下代码: trait TFn1B { type In type Out type Apply[T : In] : Out } trait TFn1[I,O] extends TFn1B { type In = I type Out = O } trait [F1 : TFn1[_,_],F2 : TFn1[_,_]] extends TFn1[F1#In,F2#Out] { type Apply[T] = F2#Apply[F1#Apply[T]] }
我有以下代码:
trait TFn1B { type In type Out type Apply[T <: In] <: Out } trait TFn1[I,O] extends TFn1B { type In = I type Out = O } trait >>[F1 <: TFn1[_,_],F2 <: TFn1[_,_]] extends TFn1[F1#In,F2#Out] { type Apply[T] = F2#Apply[F1#Apply[T]] } 它在Scala 2.9.1上编译而没有警告或错误. 但是在当前的2.10版本中,我收到以下错误消息: Fun.scala:12: error: illegal inheritance; self-type this.>>[F1,F2] does not conform to this.TFn1[_$1,_$4]'s selftype this.TFn1[_$1,_$4] trait >>[F1 <: TFn1[_,F2#Out] { ^ one error found 这是一个回归还是代码不健全,编译器最近才开始捕捉它? 解决方法
对我来说这看起来像个错误.对超类的类型参数没有任何限制,但更重要的是,-explaintypes的跟踪看起来很可疑:
scala> trait >>[F1 <: TFn1[_,F2#Out] { | type Apply[T] = F2#Apply[F1#Apply[T]] | } <console>:9: error: illegal inheritance; self-type >>[F1,F2] does not conform to TFn1[_$1,_$4]'s selftype TFn1[_$1,_$4] trait >>[F1 <: TFn1[_,F2#Out] { ^ >>[F1,F2] <: TFn1[_$1,_$4]? TFn1[_$1,_$4] <: TFn1[_$1,_$4]? _$1 <: _$1? _$1 <: Nothing? <notype> <: Nothing? false Any <: Nothing? <notype> <: Nothing? false false false Any <: _$1? Any <: Nothing? <notype> <: Nothing? false false false false false false 具体来说,我不明白它是如何或为什么不能证明TFn1 [_ $1,_ $4]<:TFn1 [_ $1,_ $4]甚至_ $1<:_ $1. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |