Skip to content

incorrect Suspicious top-level unqualified call warning message #20651

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

Open
xuwei-k opened this issue Jun 20, 2024 · 1 comment
Open

incorrect Suspicious top-level unqualified call warning message #20651

xuwei-k opened this issue Jun 20, 2024 · 1 comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Jun 20, 2024

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?

@xuwei-k xuwei-k added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 20, 2024
@som-snytt
Copy link
Contributor

That is a good one. Arguably, it is still "suspicious" because of the all bugs or dubiousness in constructor arg position. It isn't top-level, of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:bug
Projects
None yet
2 participants