Open
Description
Compiler version
3.5.0-RC1
Minimized example
scalaVersion := "3.5.0-RC1"
scalacOptions += "-explain"
package example
object A {
def main(args: Array[String]): Unit = {
println(new B(getClass.getName){}.x) // warn
println(new B(getClass.getName).x) // no warn
}
}
class B(val x: String)
Output Error/Warning message
[warn] 7 | println(new B(getClass.getName){}.x)
[warn] | ^^^^^^^^
[warn] | Suspicious top-level unqualified call to getClass
[warn] |-----------------------------------------------------------------------------
[warn] | Explanation (enabled by `-explain`)
[warn] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[warn] | Top-level unqualified calls to AnyRef or Any methods such as getClass are
[warn] | resolved to calls on Predef or on imported methods. This might not be what
[warn] | you intended.
[warn] -----------------------------------------------------------------------------
[warn] one warning found
Why this Error/Warning was not helpful
This .getClass
call is not Predef.getClass
because run result is example.A$
Suggested improvement
maybe don't report warn?