bug
bug copied to clipboard
Cake pattern imports are not treated as well as traditional
I'm using following definition to show difference in way compiler handles cake pattern and normal imports:
trait Bound {
type Param
type Kind[P <: Param]
}
object Bound {
type Aux[X, U[_ <: X]] = Bound {
type Param = X
type Kind[P <: Param] = U[P]
}
}
If I arrange imports in traditional way it compiles fine:
object Declare {
trait A
trait F[_ <: A]
}
object Use {
import Declare._
type Check = Bound.Aux[A, F]
}
But if I'd like to employ cake pattern to carry imports the compilation fails:
trait Declare {
trait A
trait F[_ <: A]
}
trait Use extends Declare {
type Check = Bound.Aux[A, F]
}
The compiler error:
error: kinds of the type arguments (Use.this.A,Use.this.F) do not conform to the expected kinds of the type parameters (type X,type U).
Use.this.F's type parameters do not match type U's expected parameters:
type _ (in trait F)'s bounds <: Declare.this.A are stricter than type _'s declared bounds <: X
type Check = Bound.Aux[A, F]
^
And If I define types inside a trait without cake pattern it still fails:
trait Declare {
trait A
trait F[_ <: A]
}
object Declare extends Declare
object Use {
import Declare._
type Check = Bound.Aux[A, F]
}
The compiler error:
error: kinds of the type arguments (Declare.A,Declare.F) do not conform to the expected kinds of the type parameters (type X,type U).
Declare.F's type parameters do not match type U's expected parameters:
type _ (in trait F)'s bounds <: this.A are stricter than type _'s declared bounds <: X
type Check = Bound.Aux[A, F]
^
scalac -version
Scala compiler version 2.11.8-20160304-000000-1706a37eb8
java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
As first triage: Having reviewed your code, I think your use case is valid and your code should be correct. I'd expect this to work in Dotty. (Sorry for not checking, on phone). The error message, if trustworthy, suggests than type variable X in the declared bound is not getting replaced by the corresponding argument prior to checking.
$ ~/dotty/dotty-0.10.0-RC1/bin/dotc -explain t10518.scala
-- [E057] Type Mismatch Error: t10518.scala:23:28 ------------------------------
23 | type Check = Bound.Aux[A, F]
| ^
|Type argument Use.this.F does not conform to upper bound [_$1 <: Use.this.A] => Any
one error found