몇몇 잘 알려진 타입과 멤버가 없는 타입(“마커 인터페이스”)은 이 경고에서 제외돼요.
예를 들어 Comparable는 경고가 나요. 비교를 전혀 하지 않는다면 제약이 더 이상 필요 없거나, 비교하는 걸 빠뜨렸을 수도 있겠죠.
scala> def inspect[A: Comparable] = "57".toInt
1 warning found
-- [E198] Unused Symbol Warning: -----------------------------------------------
1 |def inspect[A: Comparable] = "57".toInt
| ^
| unused implicit parameter
def inspect[A](using evidence$1: Comparable[A]): Int
이렇게 풀어 쓴 형태에서 사용하지 않는다고 표시해야 할 거예요:
scala> def inspect[A](item: A)(using @unused witness: Comparable[A]) = item.toString
def inspect[A](item: A)(using witness: Comparable[A]): String
이게 @nowarn보다 조금 더 깔끔하지만, 후자는 컨텍스트 바운드 표기에서도 쓸 수 있어요.
(이름으로 검사하던 건 다음 선택지가 생기기 전일 것 같아요
-Wunused:explicits,implicits,synthetics
사실 Scala 3에는 아직 synthetics가 없고 Scala 2에만 있어요:
-Wunused:synthetics Warn if a synthetic implicit parameter (context bound) is unused.
-Wunused:nowarn Warn if a @nowarn annotation does not suppress any warnings.
-Wunused:params Enable -Wunused:explicits,implicits,synthetics.
팬데믹 초기에 추가됐는데, 아마 시간을 보내려던 거겠죠.)
영어에서 번역·원문 보기Certain familiar types are exempt from this warning, as are memberless types (“marker interfaces”).
Comparable, for instance, triggers it. If nothing gets compared, perhaps the constraint has become unnecessary, or perhaps you neglected to make a comparison.
scala> def inspect[A: Comparable] = "57".toInt
1 warning found
-- [E198] Unused Symbol Warning: -----------------------------------------------
1 |def inspect[A: Comparable] = "57".toInt
| ^
| unused implicit parameter
def inspect[A](using evidence$1: Comparable[A]): Int
I believe you have to mark it unused in this expanded version:
scala> def inspect[A](item: A)(using @unused witness: Comparable[A]) = item.toString
def inspect[A](item: A)(using witness: Comparable[A]): String
That's somewhat cleaner than @nowarn, although the latter accommodates context-bound notation.
(I suspect name-based checks date to before selecting
-Wunused:explicits,implicits,synthetics
In fact, synthetics isn't available in Scala 3 yet, only Scala 2:
-Wunused:synthetics Warn if a synthetic implicit parameter (context bound) is unused.
-Wunused:nowarn Warn if a @nowarn annotation does not suppress any warnings.
-Wunused:params Enable -Wunused:explicits,implicits,synthetics.
That arrived near the pandemic's beginning, presumably as a way of filling the hours.)