scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Compiler cannot identify the equivalence of two abstract types that resolves to identical symbol #12046

Open tribbloid opened 4 years ago

tribbloid commented 4 years ago

(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:

dwijnand commented 3 years ago

I'm not 100% certain, but the fact that I can be convinced it should compile and the fact that it does in Dotty strengthens that for me. The parent trait (Super1) part of it is also interesting - are type parameters different than this.type, in terms of soundness, here? 🤔

SethTisue commented 3 years ago

In general, dealiasing is a fraught topic in scalac and there are lot of issues in the general area of "this should have been dealiases" what wasn't. I wonder if this might actually be a duplicate?

tribbloid commented 3 years ago

@SethTisue are there other tickets caused by dealiasing of non-this type?

SethTisue commented 3 years ago

I don't know. It's difficult, looking at multiple reports like this, to determine which ones are the “same” or not. It's difficult to even find tickets which are about dealiasing. (I only created the "dealias" label just now.)

som-snytt commented 3 years ago

"Issue tracker cannot identify the equivalence of two abstract tickets that resolve to the identical issue."