Skip to content

Missing warning for unused method of anonymous class #22681

Closed
@som-snytt

Description

@som-snytt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:lintingLinting warnings enabled with -W or -Xlintitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions