bug
bug copied to clipboard
Better tracking of inferred types and constraints for lint analysis
Welcome to Scala version 2.11.6-20150309-134842-c11032c6b1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_40).
Type in expressions to have them evaluated.
Type :help for more information.
scala> trait T[A] ; class C extends T[Any]
defined trait T
defined class C
scala> def f[A](t: T[A]) = ()
f: [A](t: T[A])Unit
scala> f(new C)
<console>:11: warning: a type was inferred to be `Any`; this may indicate a programming error.
f(new C)
^
Imported From: https://issues.scala-lang.org/browse/SI-9211?orig=1 Reporter: @som-snytt Affected Versions: 2.11.6 See #9209, #8861
From https://github.com/scala/bug/issues/5898
$ skala -Xlint:infer-any
Welcome to Scala 2.13.0 (OpenJDK 64-Bit Server VM 11.0.1)
scala> List(1 -> "a", 2 -> "b", 3) map { p => val (a,b) = p; a + " -> " + b } //print
^
warning: method any2stringadd in object Predef is deprecated (since 2.13.0): Implicit injection of + is deprecated. Convert to String to call +
scala.MatchError: 3 (of class java.lang.Integer)
at .$anonfun$res0$1(<console>:1)
at scala.collection.immutable.List.map(List.scala:224)
... 32 elided
scala> List(1 -> "a", 2 -> "b", 3) map { p => val (a,b) = p; a + " -> " + b } //print
scala.collection.immutable.List.apply[Any](scala.Predef.ArrowAssoc[Int](1).->[String]("a"), scala.Predef.ArrowAssoc[Int](2).->[String]("b"), 3).map[String](((p: Any) => {
val x$1 = (p: @scala.unchecked) match {
case scala.Tuple2((a @ _), (b @ _)) => scala.Tuple2.apply[Any, Any](a, b)
};
val a = x$1._1;
val b = x$1._2;
scala.Predef.any2stringadd[Any](a).+(" -> ").+(b)
})) // : List[String]
scala> List(1 -> "a", 2 -> "b", 3)
^
warning: a type was inferred to be `Any`; this may indicate a programming error.
res3: List[Any] = List((1,a), (2,b), 3)
scala> Option.empty[Int].contains("") || false // this does not throw an error, even though a type was inferred to be `Any`
val res1: Boolean = false
via https://github.com/scala/bug/issues/12320