Некоторые известные типы исключены из этой проверки, как и типы без членов (“маркерные интерфейсы”).
Например, 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.)