Closed Atry closed 6 years ago
A workaround
def workaround(a: Any): mutable.Buffer[_ <: a.type] = {
def aux[A](buffer: mutable.Buffer[A]): mutable.Buffer[_ <: A] = buffer
aux[a.type](mutable.Buffer.empty[a.type])
}
That does look like a bug.
But isn't the existential redundant here? Given that a.type
is a singleton type, surely _ <: a.type =:= a.type
? In which case a simpler equivalent signature would be,
def workaround(a: Any): mutable.Buffer[a.type] = ...
That's the point. (_ <: a.type) =:= a.type
is correct. However, scalac does not realise that. At least scalac did not know mutable.Buffer[a.type] <:< mutable.Buffer[_ <: a.type]
if a
is Any
.
Confirming that this compiles as expected in Dotty.
PR against Lightbend Scala is here: https://github.com/scala/scala/pull/6155.
The Scala version is TLS 2.12.1