Skip to content

-Wunused:all and named function arguments #16678

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
amumurst opened this issue Jan 13, 2023 · 2 comments · Fixed by #16684
Closed

-Wunused:all and named function arguments #16678

amumurst opened this issue Jan 13, 2023 · 2 comments · Fixed by #16684
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Milestone

Comments

@amumurst
Copy link

amumurst commented Jan 13, 2023

I tried adding the new unused flag (from #16157) to my work codebase and was surprised that it warned when a named arguments function defined inline gives unused warnings. This is even if it uses underscore.

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"

def foo(func: Int => String, value: Int): String = func(value)

println(foo(number => number.toString, value = 5)) //No warn
println(foo(func = number => number.toString, value = 5)) ///Warns twice
println(foo(func = _.toString, value = 5)) //Warns once

Output

[warn] ./unused-function-param.sc:7:20: unused explicit parameter
[warn] println(foo(func = number => number.toString, value = 5)) //Warns twice
[warn]                    ^^^^^^
[warn] ./unused-function-param.sc:7:27: unused local definition
[warn] println(foo(func = number => number.toString, value = 5)) //Warns twice
[warn]                           ^
[warn] ./unused-function-param.sc:8:20: unused local definition
[warn] println(foo(func = _.toString, value = 5)) //Warns once
[warn]  

Expectation

There is nothing unused here as far as I can tell, so it should not give a warning.

@amumurst amumurst added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2023
@amumurst
Copy link
Author

Another similar-ish reproduction

def foo(a: Option[String]) = a.foreach(println)
val x: Option[Int] = Some(1)
foo(a = x.map(_.toString)) //Warns
foo(x.map(_.toString)) //No warn

@szymon-rd szymon-rd added area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2023
@Kordyjan Kordyjan added this to the 3.3.0 backports milestone Jan 13, 2023
@PaulCoral
Copy link
Contributor

Fixed here #16684

szymon-rd added a commit that referenced this issue Jan 18, 2023
Fixes #16678. The issue is related to the second tree traverser (needed
as miniphase traverser do not cover every cases).

Symbols are added to a set during the traversal of their own definition
to avoid recording recursive. In the second tree traverser this symbol
is never removed, so the following usage are never cached, resulting in
false positive.

@szymon-rd
@Kordyjan Kordyjan modified the milestones: 3.3.0 backports, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants