According to section 6.19 of the Scala Language Specification this for loop:
for (e <-p) e\'
is translated to:
p <- e
The translation you get from specification is actually
list.withFilter{case b: B => true; case _ => false}.foreach{case b: B => println(b)}
but it still compiles and works. It seems like Scala is losing the case
and translating to
list.withFilter{case b: B => true; case _ => false}.foreach{b: B => println(b)}
which would give the same error.
This turns out to be a known and old bug: https://github.com/scala/bug/issues/900.
Workaround provided there:
object Typed { def unapply[A](a: A) = Some(a) }
for { Typed(b: B) <- list } println(b)