Open
Description
Reproduction steps
Scala version: 2.13.9
scala> sealed trait T; class C extends T
trait T
class C
scala> List.empty[T].contains("foo") // good: warns
^
warning: a type was inferred to be `Object`; this may indicate a programming error.
val res0: Boolean = false
scala> List.empty[C].contains("foo") // good: warns
^
warning: a type was inferred to be `Object`; this may indicate a programming error.
val res1: Boolean = false
scala> sealed trait T2; case class C2(foo: Int) extends T2
trait T2
class C2
scala> List.empty[T2].contains("foo") // good: warns
^
warning: a type was inferred to be `Object`; this may indicate a programming error.
val res2: Boolean = false
scala> List.empty[C2].contains("foo") // BAD: does NOT warn
val res3: Boolean = false
Problem
-Xlint:infer-any
isn't triggering; seemingly because scalac is inferring Serializable
in the no-warning case above. Seems like Serializable
(and possibly some other things, like Product
) should be warned on as well, or there should be another linter added for inferences to those general types. Otherwise, you miss potential mistakes when these other generic base types can be inferred.