-
Notifications
You must be signed in to change notification settings - Fork 183
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
Support RemoveUnused in Scala 3.4+ #1728
Conversation
cf2ca39
to
37cd1ef
Compare
0acaa71
to
0207e37
Compare
Trying to understand why unused warnings don't show up as diagnostics in the SemanticDB files produced by dotty
|
Looks like we don't actually write them :| I will ask someone to take a look. |
@tgodzik I came to the same (sad) conclusion and was about to open a ticket on dotty |
I will try a quick look, but that means it will mos tlikely be in 3.3.1 :/ |
Any updates regarding this PR? |
I think we are waiting for the new Scala 3 release |
Indeed, as soon as I see activity on the release train, I'll put that back in shape (and align with #1800). The dotty PR has been marked as |
From the dotty PR
|
0698713
to
acbd4b7
Compare
7ba8bef
to
945baa2
Compare
@@ -67,7 +64,7 @@ object Main { | |||
} | |||
``` | |||
|
|||
Remove unused pattern match variables: | |||
Remove unused pattern match variables (requires `-Wunused:unsafe-warn-patvars` on Scala 3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -9,7 +9,7 @@ title: Installation | |||
|
|||
**Java LTS (8, 11, 17 or 21)** | |||
|
|||
**Scala 2.12, 2.13 or 3.x** (all rules are not available for Scala 3.x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only ExplicitResultTypes
remains unsupported, and it's documented in rule docs, so I think we can drop this verbose disclaimer
version.startsWith("3.0") || | ||
version.startsWith("3.1") || | ||
version.startsWith("3.2") || | ||
version.startsWith("3.3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.3.3 is likely to get the semanticdb fix but I'll update when I see it happening in a RC
case _ => importee.pos | ||
} | ||
isUnusedImport.exists { unused => | ||
unused.start <= pos.start && pos.end <= unused.end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semanticdb diagnostics emitted by Scala 3 can be wider than those emiited by Scala 2's semanticdb-scalac (which do match the tree positions apart from renames, handled above)
@@ -87,7 +84,7 @@ object Main { | |||
} | |||
``` | |||
|
|||
Remove unused function parameters: | |||
Remove unused function parameters (Scala 2 only): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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), so I am leaving this out for now
$ 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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -107,6 +107,7 @@ Use `MethodSignature.parameterLists` to look up parameters of a method. | |||
def printMethodParameters(symbol: Symbol): Unit = { | |||
symbol.info.get.signature match { | |||
case signature @ MethodSignature(typeParameters, parameterLists, _) => | |||
println("signature = " + signature) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in ScalafixBuild
enabled more unused warnings on the builds
First half of #1682
scala/scala3#16157