Skip to content

Missing warning for unused method of anonymous class #22681

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

Closed
som-snytt opened this issue Feb 28, 2025 · 0 comments · Fixed by #22729
Closed

Missing warning for unused method of anonymous class #22681

som-snytt opened this issue Feb 28, 2025 · 0 comments · Fixed by #22729
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@som-snytt
Copy link
Contributor

som-snytt commented Feb 28, 2025

Compiler version

3.7

Minimized code

//> using options -Vprint:typer -Wunused:all

class C {
  def f: Runnable = new Runnable {
    def run() = ()
    def g = 42
  }
}

Output

Dotty is silent but Scala 2 says

unused-priv.scala:7: warning: private method g in <$anon: Runnable> is never used
    def g = 42
        ^

because the method is made private.

Expectation

A warning that the method is unused (because effectively private if not actually).

Note that the inferred type in Scala 2 is the refinement. An expected type is required for the behavior.

As noticed by tpolecat https://mastodon.social/@tpolecat/114078274060499612

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 28, 2025
@Gedochao Gedochao added area:linting Linting warnings enabled with -W or -Xlint and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 3, 2025
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants