Skip to content

Infer Any/AnyVal warning suppressed by inclusion in Unit block #12441

@blast-hardcheese

Description

@blast-hardcheese

reproduction steps

Reproduction repo: blast-hardcheese/scala-bug-xlint-infer-any, includes all compiler output for all versions.

using representative Scala versions from 2.11.0 through 2.13.6,

object Bogus {
  Option.empty[String].contains(1234) // Emits a warning

  def should(func: => Unit): Unit = func

  should {
    Option.empty[String].contains(1234) // Does not warn
  }

  println(Option.empty[String].contains(1234)) // does not warn
}

should output three warnings (as the code is the same in both places; if it warns in one place, it should warn in the others) but only one warning is emitted for all versions from 2.11.0 onwards.

problem

It seems as though being part of a block whose result type gets coerced to Unit disables the following warning:

a type was inferred to be `Any`; this may indicate a programming error.

This is particularly devastating when it is observed that this is a common pattern in scalatest. As a result, nonsensical tests fail to flag -Xfatal-warnings and defects are subject to being caught by the runtime.

This may be related to #12320 (and #9211, by association), but as this is explicitly a regression in the compiler from 2.10.7, I'm calling this out separately.


Thank you all for your work, it is a pleasure to use what you have built.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions