Skip to content

Probably regression in v3.7.x: false positive warning with -Wunused:explicits #23349

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
satorg opened this issue Jun 10, 2025 · 3 comments · May be fixed by #23351
Open

Probably regression in v3.7.x: false positive warning with -Wunused:explicits #23349

satorg opened this issue Jun 10, 2025 · 3 comments · May be fixed by #23351
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@satorg
Copy link

satorg commented Jun 10, 2025

Compiler version

The issue is reproducible starting with Scala v3.7.x: 3.7.0, 3.7.1 as well as 3.7.2-RC1-bin-20250609-41cf6eb-NIGHTLY.
It does not appear in Scala v3.3.x and v3.6.x.

Minimized code

//> using scala 3.7.nightly
//> using options -Wunused:explicits

// An external class that doesn't get its own `copy` method.
class Foo(val a: String, val b: Int)

//
// Example 1: add `copy` method via an extension method.
//
extension (self: Foo)
  def copy(a: String = self.a, b: Int = self.b): Foo = Foo(a, b)

//
// Example 2: implement `copyFoo` with parameter groups.
//
def copyFoo(foo: Foo)(a: String = foo.a, b: Int = foo.b): Foo = Foo(a, b)

Output

Starting with Scala v3.7.x only:

-- [E198] Unused Symbol Warning: .../unused-explicit-param.scala:10:11 
10 |extension (self: Foo)
   |           ^^^^
   |           unused explicit parameter in extension method copy
-- [E198] Unused Symbol Warning: .../unused-explicit-param.scala:16:12 
16 |def copyFoo(foo: Foo)(a: String = foo.a, b: Int = foo.b): Foo = Foo(a, b)
   |            ^^^
   |            unused explicit parameter
2 warnings found

No warnings in Scala v3.6.4 and v3.3.6.

Expectation

No warning whatsoever.

@satorg satorg added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 10, 2025
@satorg satorg changed the title Probably regression in v3.7.x: false positive warning with -Wunused:explicit Probably regression in v3.7.x: false positive warning with -Wunused:explicits Jun 10, 2025
@SethTisue
Copy link
Member

@som-snytt a bit of collateral damage from #20894 perhaps?

@som-snytt
Copy link
Contributor

som-snytt commented Jun 10, 2025

It's not designed to detect usages only in default args, but I also thought it doesn't warn for receivers of extensions.

Previous versions were false negatives anyway.

Edit: forgot to say, thanks for the report!

Also, thanks for the using directives, and for spelling "its" correctly. It's the little things!

Also thanks @SethTisue you are the whitelighter.

@som-snytt som-snytt self-assigned this Jun 10, 2025
@som-snytt som-snytt 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 Jun 10, 2025
@satorg
Copy link
Author

satorg commented Jun 10, 2025

Btw, just realized that it's also the case with implict parameters too:

//> using scala 3.7.nightly
//> using options -Wunused:implicits

class Foo(val a: String)

def copyFoo(using foo: Foo)(a: String = foo.a): Foo = Foo(a)

which triggers

-- [E198] Unused Symbol Warning: .../unused-implicit-params.scala:7:18
7 |def copyFoo(using foo: Foo)(a: String = foo.a): Foo = Foo(a)
  |                  ^^^
  |                  unused implicit parameter

in Scala 3.7 only.

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