Why has the Scala compiler become more strict regarding self types in 2.10?

I have the following code:

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]] } 

It compiles on Scala 2.9.1 without warning or error.

But in the current build 2.10, I get the following error message:

 Fun.scala:12: error: illegal inheritance; self-type this.>>[F1,F2] does not conform to this.TFn1[_$1,_$4] selftype this.TFn1[_$1,_$4] trait >>[F1 <: TFn1[_, _], F2 <: TFn1[_, _]] extends TFn1[F1#In, F2#Out] { ^ one error found 

Is this a regression or is the code unsatisfactory, and has the compiler just begun to catch it recently? If the code is wrong, what will work to make it work again?

+4
source share
2 answers

This seems like a mistake. There are no restrictions on parameters like superclasses, but moreover, tracing for -explaintypes seems suspicious to me:

 scala> trait >>[F1 <: TFn1[_, _], F2 <: TFn1[_, _]] extends TFn1[F1#In, 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] selftype TFn1[_$1,_$4] trait >>[F1 <: TFn1[_, _], F2 <: TFn1[_, _]] extends TFn1[F1#In, 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 

In particular, I do not understand how and why he cannot prove that TFn1[_$1,_$4] <: TFn1[_$1,_$4] or even _$1 <: _$1 .

+2
source
+3
source

Source: https://habr.com/ru/post/1392577/


All Articles