Skip to content

Commit

Permalink
fix UnusedScalafixSuppression warnings on Scala 3 scalafix invocations
Browse files Browse the repository at this point in the history
Since ExplicitResultTypes is unavailable in Scala 3, some silencers are
rightfully detected as unused for that invocation. Qualifying these silencers
by suffixing ExplicitResultTypes does not help, since EscapeHatch is not aware
of which rules are executed, so we need to address the problem differently.

- For the (v0) signature, this removes the silencer to be explicit about the
  type since there is no reason (except compatibility) to keep it this way.
  Since this is the old API and a very specific class, it's unlikely that will
  will cause linking errors when running community rules with existing
  versions.
- For test suites where we DO want an explicit type, this turns private the
  terms that ExplicitResultTypes warns on to stop triggering it. However, this
  triggers RemoveUnused, but since it is now common to both Scala 2 and Scala 3
  and, it does not trigger UnusedScalafixSuppression in any invocation.
  • Loading branch information
bjaglin committed May 1, 2024
1 parent 8bde76c commit 22f09a4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion project/Mima.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Mima {
ProblemFilters.exclude[Problem]("scalafix.internal.*"),
ProblemFilters.exclude[Problem]("scala.meta.internal.*"),
// Exceptions
ProblemFilters.exclude[DirectMissingMethodProblem]("scalafix.Versions.scala211")
ProblemFilters.exclude[DirectMissingMethodProblem]("scalafix.v0.Signature#Self.syntax")
)
}
}
6 changes: 2 additions & 4 deletions scalafix-core/src/main/scala/scalafix/v0/Signature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ object Signature {
}

final case class Self(name: String) extends Signature {
override def syntax =
throw new UnsupportedOperationException(
"No longer supported."
) // scalafix:ok
override def syntax: String =
throw new UnsupportedOperationException("No longer supported.")
override def structure: String = s"""Signature.Self("$name")"""
override def toString: String = syntax
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package test
object DenotationOpsTest {
def m(x: Int, y: String): List[String] = List(y)
var x = true
val y = m(42, "hey")
private val y = m(42, "hey")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package test

class TypesTest {
val a = 42
val b = List(42)
private val b = List(42)
class Inner
val c = new TypesTest
val d = new c.Inner
val e = null.asInstanceOf[TypesTest#Inner]
private val e = null.asInstanceOf[TypesTest#Inner]
val f: {
def foo(a: Int): Int
def bar(a: Int): Int
Expand Down

0 comments on commit 22f09a4

Please sign in to comment.