Skip to content

Subtyping breaks under a dependent prefix? #4908

Open
@Blaisorblade

Description

@Blaisorblade

Split out of #4902.
In the code below, x.to(g.MSetFactory) works in v1 but not in f3, so it seems clear it's a bug, probably involving asSeenFrom somewhere. Sadly Scalac can't handle this either.

object Test {
  trait A
  trait B
  trait TestConstructor1 { type F[X <: A]
    trait FromSet[C[_ <: A with B]]

    trait MSetLike[X <: A with B, This <: MSet[X] with MSetLike[X, This]] {
      def to[C[X <: A with B] <: MSet[X] with MSetLike[X, C[X]]](fi: FromSet[C]): C[X] = ???
    }
    trait MSet[X <: A with B] extends MSetLike[X, MSet[X]]
    object MSetFactory extends FromSet[MSet]
  }

  trait TestConstructor4[D] {
    trait TestConstructor5[E] {
      trait FromSet[C[_ <: D with E]]

      trait MSetLike[X <: D with E, This <: MSet[X] with MSetLike[X, This]] {
        def to[C[X <: D with E] <: MSet[X] with MSetLike[X, C[X]]](fi: FromSet[C]): C[X] = ???
      }
      trait MSet[X <: D with E] extends MSetLike[X, MSet[X]]
      object MSetFactory extends FromSet[MSet]
    }
  }

  type C = A & B
  val v1: TestConstructor1 => Unit = { f =>
    type P[a <: A] = f.F[a]

    type P1[c <: C] = f.MSet[c]
      (f.MSetFactory: f.FromSet[f.MSet]): Unit
      (x: P1[C]) => x.to(f.MSetFactory)
  }

  def f3(f: TestConstructor4[A])(g: f.TestConstructor5[B]): Unit = {
    type P1[c <: C] = g.MSet[c]
      (g.MSetFactory: g.FromSet[g.MSet]): Unit
      (x: P1[C]) => x.to(g.MSetFactory)
      (x: P1[C]) => x.to[g.MSet](g.MSetFactory)
  }
}

gives

- [E007] Type Mismatch Error: tests/pos/i4884c.scala:37:9 ---------------------
37 |      (g.MSetFactory: g.FromSet[g.MSet]): Unit
   |       ^^^^^^^^^^^^^
   |       found:    g.MSetFactory.type
   |       required: g.FromSet[g.MSet]
   |
-- [E007] Type Mismatch Error: tests/pos/i4884c.scala:38:27 --------------------
38 |      (x: P1[C]) => x.to(g.MSetFactory)
   |                         ^^^^^^^^^^^^^
   |                         found:    g.MSetFactory.type
   |                         required: g.FromSet[g.MSet]
   |
-- [E007] Type Mismatch Error: tests/pos/i4884c.scala:39:35 --------------------
39 |      (x: P1[C]) => x.to[g.MSet](g.MSetFactory)
   |                                 ^^^^^^^^^^^^^
   |                                 found:    g.MSetFactory.type
   |                                 required: g.FromSet[g.MSet]
   |
three errors found

That's from some code in tests/run/colltest5/ that failed when I oversimplified typeApplications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:typerbacklogNo work planned on this by the core team for the time being.itype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions