Skip to content
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

RemoveUnused: detect unused function parameters in Scala 3 #1937

Open
bjaglin opened this issue Feb 21, 2024 · 4 comments · May be fixed by #1951
Open

RemoveUnused: detect unused function parameters in Scala 3 #1937

bjaglin opened this issue Feb 21, 2024 · 4 comments · May be fixed by #1951

Comments

@bjaglin
Copy link
Collaborator

bjaglin commented Feb 21, 2024

Despite the presence of -Wunused:params and the explicit mention of it in scala/scala3#16157, I did not manage to get diagnostics (nor warnings) for unused parameters with scala 3.4.0-RC2, so the feature is currently documented/tested as Scala2-only.

We probably need to report this upstream.

$ metap ./scalafix-tests/input/target/jvm-3.4.0-RC2/meta/META-INF/semanticdb/scalafix-tests/input/src/main/scala/test/removeUnused/RemoveUnusedParams.scala.semanticdb 
scalafix-tests/input/src/main/scala/test/removeUnused/RemoveUnusedParams.scala
------------------------------------------------------------------------------

Summary:
Schema => SemanticDB v4
Uri => scalafix-tests/input/src/main/scala/test/removeUnused/RemoveUnusedParams.scala
Text => empty
Language => Scala
Symbols => 11 entries
Occurrences => 28 entries

Symbols:
local0 => param unused: String
local1 => param unused: String
local2 => param used: String
local3 => param unused: Long
local4 => implicit param string: String
test/removeUnused/UnusedParams. => final object UnusedParams extends Object { self: UnusedParams.type => +5 decls }
test/removeUnused/UnusedParams.f. => val method fFunction1[String, Unit]
test/removeUnused/UnusedParams.ff. => val method ffFunction1[String, Unit]
test/removeUnused/UnusedParams.fs. => val method fsFunction2[String, Long, Unit]
test/removeUnused/UnusedParams.g(). => method g(x: Function1[String, Unit]): Unit
test/removeUnused/UnusedParams.g().(x) => param x: Function1[String, Unit]

Occurrences:
[3:8..3:12) => test/
[3:13..3:25) <= test/removeUnused/
[5:7..5:19) <= test/removeUnused/UnusedParams.
[6:6..6:7) <= test/removeUnused/UnusedParams.f.
[6:9..6:15) => scala/Predef.String#
[6:19..6:23) => scala/Unit#
[6:26..6:32) <= local0
[6:36..6:43) => scala/Predef.println(+1).
[7:6..7:8) <= test/removeUnused/UnusedParams.ff.
[7:12..7:18) <= local1
[7:20..7:26) => scala/Predef.String#
[7:31..7:38) => scala/Predef.println(+1).
[8:6..8:8) <= test/removeUnused/UnusedParams.fs.
[8:12..8:16) <= local2
[8:18..8:24) => scala/Predef.String#
[8:26..8:32) <= local3
[8:34..8:38) => scala/Long#
[8:43..8:50) => scala/Predef.println(+1).
[8:51..8:55) => local2
[9:6..9:7) <= test/removeUnused/UnusedParams.g().
[9:8..9:9) <= test/removeUnused/UnusedParams.g().(x)
[9:11..9:17) => scala/Predef.String#
[9:21..9:25) => scala/Unit#
[9:28..9:32) => scala/Unit#
[9:35..9:38) => scala/Predef.`???`().
[10:2..10:3) => test/removeUnused/UnusedParams.g().
[10:13..10:19) <= local4
[10:23..10:30) => scala/Predef.println(+1).

Originally posted by @bjaglin in #1728 (comment)

@bjaglin bjaglin changed the title Despite the presence of -Wunused:params and the explicit mention of it in https://github.com/lampepfl/dotty/pull/16157, I did not manage to get diagnostics (nor warnings), so I am leaving this out for now RemoveUnused: detect unused function parameters in Scala 3 Feb 21, 2024
@bjaglin bjaglin linked a pull request Mar 3, 2024 that will close this issue
@bjaglin bjaglin linked a pull request Jul 29, 2024 that will close this issue
@bjaglin
Copy link
Collaborator Author

bjaglin commented Aug 1, 2024

FTR, not fixed as of

[error] (expect2_13Target3_5_0-RC6 / Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] (expect2_13Target3_3_4-RC1 / Test / test) sbt.TestsFailedException: Tests unsuccessful

(tested via #1951)

@tgodzik
Copy link
Contributor

tgodzik commented Aug 2, 2024

Does it not produce warnings or are those warnings not in semanticdb?

@bjaglin
Copy link
Collaborator Author

bjaglin commented Aug 4, 2024

@tgodzik no warning is emitted by the compiler, I guess it's just a missing feature

// UnusedParams.scala

import java.util.List

object UnusedParams {
  val f: String => Unit = unused => println("f")
  val ff = (unused: String) => println("f")
  val fs = (used: String, unused: Long) => println(used)
  def g(x: String => Unit): Unit = ???
  g{implicit string => println("g")}
}
  /tmp scala-cli compile --scala 2.13.14 -Wunused UnusedParams.scala
Compiling project (Scala 2.13.14, JVM (21))
[warn] ./UnusedParams.scala:1:1
[warn] Unused import
[warn] import java.util.List
[warn] ^^^^^^^^^^^^^^^^^^^^^
[warn] ./UnusedParams.scala:4:27
[warn] parameter unused in anonymous function is never used
[warn]   val f: String => Unit = unused => println("f")
[warn]                           ^^^^^^
[warn] ./UnusedParams.scala:5:13
[warn] parameter unused in anonymous function is never used
[warn]   val ff = (unused: String) => println("f")
[warn]             ^^^^^^^^^^^^^^
[warn] ./UnusedParams.scala:6:27
[warn] parameter unused in anonymous function is never used
[warn]   val fs = (used: String, unused: Long) => println(used)
[warn]                           ^^^^^^^^^^^^
[warn] ./UnusedParams.scala:8:14
[warn] parameter string in anonymous function is never used
[warn]   g{implicit string => println("g")}
[warn]              ^^^^^^
Compiled project (Scala 2.13.14, JVM (21))
  /tmp scala-cli compile --scala 3.4.2 -Wunused:all UnusedParams.scala
Compiling project (Scala 3.4.2, JVM (21))
[warn] ./UnusedParams.scala:1:18
[warn] unused import
[warn] import java.util.List
[warn]                  ^^^^
Compiled project (Scala 3.4.2, JVM (21))

@bjaglin
Copy link
Collaborator Author

bjaglin commented Aug 4, 2024

Actually, it looks like an issue for that was recently filed: scala/scala3#20951

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants