Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing "parameterized overloaded implicit methods are not visible as view bounds" warning in Scala

Tags:

scala

Is it possible to suppress this specific warning by using @SuppressWarnings(???)? (I don't intend to use this conversion as a view bound, so the warning isn't useful.)

like image 217
Alexey Romanov Avatar asked Jul 04 '11 07:07

Alexey Romanov


2 Answers

Unfortunately not. The compiler ignores @SuppressWarnings. Also see this question.

like image 149
Jean-Philippe Pellet Avatar answered Nov 15 '22 06:11

Jean-Philippe Pellet


While you cannot suppress this warning through @SuppressWarnings, you can simply rename one of the overloads that the compiler is warning about. If you don't want to rename it because it is also explictly called, make the method non-implicit and add another (differently named) implicit conversion that forwards to the former.

In other words, you should by example turn this:

class MyClass
object MyClass {
   implicit def myConv: MyClass = error("TODO")
   implicit def myConv[X](value: X): MyClass = error("TODO")
}

into this:

class MyClass
object MyClass {
   implicit def myConv: MyClass = error("TODO")
   def myConv[X](value: X): MyClass = error("TODO") // made it non implicit
   implicit def myConv2[X](value: X): MyClass = myConv( value ) // renamed so that it is not an overload anymore
}

Note that the warning is only emitted in scala 2.9.x, it is by default not emitted anymore in scala 2.10 (but the actual problem that the warning is talking about is still there - the warning message was only removed because it was deemed too noisy with the new surge in type class usage).

like image 34
Régis Jean-Gilles Avatar answered Nov 15 '22 06:11

Régis Jean-Gilles