Skip to content

-Xlint:infer-any doesn't catch all scenarios where a type is inferred to be Any #12320

@coreywoodfield

Description

@coreywoodfield

Reproduction steps

using Scala 2.13.3,

Run scala with scala -Xlint:infer-any -Wconf:cat=lint-infer-any:error

scala> Option.empty[Int].contains("") // this errors as expected
                         ^
       error: a type was inferred to be `Any`; this may indicate a programming error.

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

or, to see type information:
This fails as expected:

scalac -Xlint:infer-any -Wconf:cat=lint-infer-any:error -Xprint:typer /dev/stdin <<<'object Main { Option.empty[Int].contains("") }'

This doesn't fail (even though it should, according to the typer output):

scalac -Xlint:infer-any -Wconf:cat=lint-infer-any:error -Xprint:typer /dev/stdin <<<'object Main { Option.empty[Int].contains("") || ??? }'

Problem

Expectation: The linter reports all instances of Any being inferred when -Xlint:infer-any is enabled
Actual: The linter sometimes doesn't report instances of Any being inferred with -Xlint:infer-any enabled

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions