Existential scope of existential typeparameter changes unexpectedly

The following fails, because the forSome existential scoping is inferred to the wrong level

case class A[T](t:T)

val isas = (1 to 4).map{ i =>
  val a: A[_] = A(i)
  (i, a)
}

val (is, as) = isas.unzip

with the error

error: No implicit view available from (Int, A[_$1]) forSome { type _$1 } => (A1, A2).
       val (is, as) = isas.unzip

Note that, surprisingly, the inferred type is (Int, A[_$1]) forSome { type _$1 } and not (Int, A[_$1] forSome { type _$1 }).


If we explicitly add type annotations as in the following example, it somehow glues the existential forSome to a and everything works

val isas2 = (1 to 4).map{ i =>
  val a: A[_] = A(i)
  (i, a): (Int, A[_])
}

val (is2, as2) = isas2.unzip

this behaviour looks very suspicuous…
why is the forSome put to the wrong place without extra type annotations?
Is this a bug?

Yep. Yep.

If you want to use existentials, use type members to encode them. You’ll be a lot happier.

1 Like

@schlichtanders Since this looks like a bug, I would suggest you, if you haven’t already, to open an issue (bug report) in https://github.com/scala/bug/issues, so as to move the discussion over there. If you could add here a link to that bug report, that would be helpful.