Skip to content

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

Open
@tribbloid

Description

@tribbloid

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dealiascompiler isn't dealiasing when it should, or vice versadependent typesfixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions