Good, but you wonβt believe it. Enabling -Yinfer-debug for your counter CanBuildFrom example,
[search] $line14.$read.$iw.$iw.build[scala.this.Int, Seq[scala.this.Int]](1, 2) with pt=generic.this.CanBuildFrom[scala.this.Nothing,scala.this.Int,Seq[scala.this.Int]] in module class $iw, eligible: fallbackStringCanBuildFrom: [T]=> generic.this.CanBuildFrom[String,T,immutable.this.IndexedSeq[T]] [solve types] solving for T in ?T inferExprInstance { tree scala.this.Predef.fallbackStringCanBuildFrom[T] tree.tpe generic.this.CanBuildFrom[String,T,immutable.this.IndexedSeq[T]] tparams type T pt generic.this.CanBuildFrom[scala.this.Nothing,scala.this.Int,Seq[scala.this.Int]] targs scala.this.Int tvars =?scala.this.Int } [search] considering no tparams (pt contains no tvars) trying generic.this.CanBuildFrom[String,scala.this.Int,immutable.this.IndexedSeq[scala.this.Int]] against pt=generic.this.CanBuildFrom[scala.this.Nothing,scala.this.Int,Seq[scala.this.Int]] [success] found SearchResult(scala.this.Predef.fallbackStringCanBuildFrom[scala.this.Int], ) for pt generic.this.CanBuildFrom[scala.this.Nothing,scala.this.Int,Seq[scala.this.Int]] [infer implicit] inferred SearchResult(scala.this.Predef.fallbackStringCanBuildFrom[scala.this.Int], )
and indeed
implicit def fallbackStringCanBuildFrom[T]: CanBuildFrom[String, T, immutable.IndexedSeq[T]] = new CanBuildFrom[String, T, immutable.IndexedSeq[T]] { def apply(from: String) = immutable.IndexedSeq.newBuilder[T] def apply() = immutable.IndexedSeq.newBuilder[T] }
What do you mean, your Iterable is not a string?
trait CanBuildFrom[-From, -Elem, +To]
Such is evil, deducing neither Nothing nor Any.
Edit: Sorry, I was wrong, I see that you did not say anything.
Update:
Since CBF is contravariant in From , CBF of String serves as CBF of Nothing .
scala> typeOf[CanBuildFrom[Nothing,Int,Seq[Int]]] <:< typeOf[CanBuildFrom[String,Int,Seq[Int]]] res0: Boolean = false scala> typeOf[CanBuildFrom[String,Int,Seq[Int]]] <:< typeOf[CanBuildFrom[Nothing,Int,Seq[Int]]] res1: Boolean = true
For example, if you need to build from immutable.Map , you need the CBF from collection.Map work.
As someone else commented, it's just weird for Nothing . But you get what you asked for. That is, you did not specify, which means that you do not mind that you will return, Vector or something else.