From 22f09a48d91c032a7b057a8ef9effbf7325033c8 Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Wed, 1 May 2024 13:36:22 +0200 Subject: [PATCH] fix UnusedScalafixSuppression warnings on Scala 3 scalafix invocations 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. --- project/Mima.scala | 2 +- scalafix-core/src/main/scala/scalafix/v0/Signature.scala | 6 ++---- .../integration/src/main/scala/test/DenotationOpsTest.scala | 2 +- .../integration/src/main/scala/test/TypesTest.scala | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/project/Mima.scala b/project/Mima.scala index ddc95cf6d..624f53b3d 100644 --- a/project/Mima.scala +++ b/project/Mima.scala @@ -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") ) } } diff --git a/scalafix-core/src/main/scala/scalafix/v0/Signature.scala b/scalafix-core/src/main/scala/scalafix/v0/Signature.scala index ef29d328c..9808987de 100644 --- a/scalafix-core/src/main/scala/scalafix/v0/Signature.scala +++ b/scalafix-core/src/main/scala/scalafix/v0/Signature.scala @@ -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 } diff --git a/scalafix-tests/integration/src/main/scala/test/DenotationOpsTest.scala b/scalafix-tests/integration/src/main/scala/test/DenotationOpsTest.scala index 7afa73f8e..00a59b77d 100644 --- a/scalafix-tests/integration/src/main/scala/test/DenotationOpsTest.scala +++ b/scalafix-tests/integration/src/main/scala/test/DenotationOpsTest.scala @@ -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") } diff --git a/scalafix-tests/integration/src/main/scala/test/TypesTest.scala b/scalafix-tests/integration/src/main/scala/test/TypesTest.scala index 55ca2ce32..0ca720690 100644 --- a/scalafix-tests/integration/src/main/scala/test/TypesTest.scala +++ b/scalafix-tests/integration/src/main/scala/test/TypesTest.scala @@ -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