Skip to content

can't existentially abstract over parameterized type F #9281

Open
@scabug

Description

@scabug

Consider the following snippet. Casting to existential causing the error "can't existentially abstract over parameterized type F".

test1 fails for both scala 2.10 and 2.11
test2 works for 2.10 but fails for 2.11
test3 works for 2.10 and 2.11

  // define container trait, type alias and value
  trait Container[F[_]]
  type CC[F[_]] = Container[F]
  val c = new CC[Option] {}

  // fails for 2.10 and 2.11
  // error: can't existentially abstract over parameterized type F
  type SomeContainer = Container[F] forSome { type F[_] }
  val test1 = c.asInstanceOf[SomeContainer]

  // works for 2.10 but fails for 2.11
  type SomeCC = CC[F] forSome { type F[_] }
  implicitly[SomeContainer =:= SomeCC]
  val test2 = c.asInstanceOf[SomeCC]

  // workaround for 2.11 but isn't it the same as test2?
  type SomeF[X] = F[X] forSome { type F[_] }
  implicitly[SomeCC =:= CC[SomeF]]
  val test3 = c.asInstanceOf[CC[SomeF]]

from my point of view test1 and test2 should work either

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions