Skip to content

False positive unused warning in 3.7 nightly on extension method with default argument #22746

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
mrdziuban opened this issue Mar 7, 2025 · 1 comment · Fixed by #22749
Closed
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@mrdziuban
Copy link

Compiler version

3.7.0-RC1-bin-20250306-73ba485-NIGHTLY

Minimized code

With -Wunused:params enabled:

import java.time.ZonedDateTime

trait Foo[A] {
  def apply(a: A, t: ZonedDateTime): A
}

extension [A](a: A)(using f: Foo[A]) {
  def foo(t: ZonedDateTime = ZonedDateTime.now): A = f(a, t)
}

Output

-- [E198] Unused Symbol Warning: /Users/matt/scala3.7-nightly-unused/src/main/scala/example/Test.scala:7:14 ------------
7 |extension [A](a: A)(using f: Foo[A]) {
  |              ^
  |              unused explicit parameter
-- [E198] Unused Symbol Warning: /Users/matt/scala3.7-nightly-unused/src/main/scala/example/Test.scala:7:26 ------------
7 |extension [A](a: A)(using f: Foo[A]) {
  |                          ^
  |                          unused implicit parameter

Expectation

Both a and f are used in def foo so they should not be reported unused

@mrdziuban mrdziuban added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 7, 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 Mar 7, 2025
@som-snytt som-snytt self-assigned this Mar 7, 2025
@som-snytt
Copy link
Contributor

I guess because defaults get dependencies they don't use.

    def foo$default$3[A >: Nothing <: Any](a: A)(using f: Foo[A]):
      java.time.ZonedDateTime @uncheckedVariance = java.time.ZonedDateTime.now()
    }

@som-snytt som-snytt marked this as a duplicate of #22748 Mar 8, 2025
sjrd added a commit that referenced this issue Mar 10, 2025
Fixes #22746 
Fixes #22748 

Default arg getters are defined with dependencies they don't use.
@sjrd sjrd marked this as not a duplicate of #22748 Mar 10, 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