开发者

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

开发者 https://www.devze.com 2023-03-17 06:27 出处:网络
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.)Unfortunately no

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.)


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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号