Skip to content

-Wunused:all and private extractor objects #16682

Closed
@amumurst

Description

@amumurst

I tried adding the new unused flag (from #16157) to my work codebase and was surprised that it warned about unused private member when used with the http library http4ss query parameter matching. A minimal reproducer independent of http4s is below.

Compiler version

With nightly: 3.3.0-RC1-bin-20230112-be10bc6-NIGHTLY

Minimized code

//> using scala "3.3.0-RC1-bin-20230112-be10bc6-NIGHTLY"
//> using option "-Wunused:all"

object myPackage:
   private object IntExtractor:
      def unapply(s: String): Option[Int] = s.toIntOption

   def isInt(s: String) = s match {
      case IntExtractor(i) => println(s"Number $i")
      case _ => println("NaN")
   }

myPackage.isInt("42")

Output

[warn] ./unused-extractor-object.sc:5:19: unused private member
[warn]    private object IntExtractor:
[warn]                   ^^^^^^^^^^^^

Expectation

IntExtractor is used when matching against the string, so it should not warn about it being unused.

Metadata

Metadata

Assignees

Labels

area:reportingError reporting including formatting, implicit suggestions, etcitype:bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions