Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better tracking of inferred types and constraints for lint analysis #9211

Open
scabug opened this issue Mar 10, 2015 · 3 comments
Open

Better tracking of inferred types and constraints for lint analysis #9211

scabug opened this issue Mar 10, 2015 · 3 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Mar 10, 2015

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)
                ^
@scabug
Copy link
Author

scabug commented Mar 10, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9211?orig=1
Reporter: @som-snytt
Affected Versions: 2.11.6
See #9209, #8861

@som-snytt
Copy link

From #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)

@som-snytt
Copy link

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 #12320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants