Open
Description
(Original post: https://stackoverflow.com/questions/62478001/in-scala-how-to-instruct-the-compiler-to-realise-the-equivalence-of-two-abstrac)
reproduction steps
using Scala (2.12.11, 2.13.2),
trait Super1[S] {
final type Out = this.type
final val out: Out = this
}
trait Super2[S] extends Super1[S] {
final type SS = S
}
case class A[S](k: S) extends Super2[S] {}
val a = A("abc")
implicitly[a.type =:= a.out.type]
// success
implicitly[a.Out =:= a.out.Out]
// success
implicitly[a.SS =:= a.out.SS]
implicitly[a.SS <:< a.out.SS]
implicitly[a.out.SS <:< a.SS]
// oops
problem
if I move:
final type Out = this.type
final val out: Out = this
to be under Super2
it will compile successfully.
the path-dependent type resolver behave inconsistently just for this case. My questions are:
-
How to visualise the type representation of abstract types? (e.g. printing a tree of all supertypes, constraints & type parameters etc.)
-
What is the root cause that cause this problem, can it be identified by the used visualisation?