Consider the following:
trait Foo {
type F[_]
type A
type FA = F[A]
def get: FA
}
class SeqStringFoo extends Foo {
type F[_] = Seq[_]
type A = String
def get: Seq[String] = Seq("hello world")
}
def exec[F <: Foo](foo: F): F
val seq1: Seq[Any] = exec(new SeqStringFoo()) // Seq[Any] = List(hello world)
val seq2: Seq[String] = exec(new SeqStringFoo()) // Error: Expression SeqIntFoo
seq2does not compile, because for some reason information of type wrapped type Stringis lost when using the type F#FA .
This does not happen if the return type is not of a higher type.
Why is this happening?
How can I get around this?
source
share