Ao inferir tipos, o compilador geralmente precisa calcular o LUB (Least Upper Bound) de uma lista de tipos. Por exemplo, o tipo de if (cond) e1 else e1
é o LUB dos tipos de e1
e e1
.
Esses tipos podem ficar muito grandes, por exemplo, tente isso em um REPL:
:type Map(1 -> (1 to 10), 2 -> (1 to 10).toList)
scala.collection.immutable.Map[Int,scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int] with Serializable{def reverse: scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]{def reverse: scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]; def dropRight(n: Int): scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]; def takeRight(n: Int): scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]; def drop(n: Int): scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]; def take(n: Int): scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]}; def dropRight(n: Int): scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]{def reverse: scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]; def dropRight(n: Int): scala.collection.immutable.Seq[Int]...
Esse commit introduziu algumas verificações de sanidade para limitar a profundidade desses tipos inferidos.
Houve algum trabalho recente para conectar ao processo de compilação para detectar tipos inferidos que demoram muito para serem calculados e sugerir locais onde uma anotação explícita de tipo pode ser prudente.