Good code red - implicit conversion


I have a little trick for forcing caller of a method to supply an exact type, disabling unwanted implicit conversions
(for example if I want to force a caller to supply BigDecimal and not Double, which has a conversion to BigDecimal).
It involves tagging a value with a trait (using shapeless @@) and my own implicit conversion.


import shapeless.tag
import shapeless.tag.@@

sealed trait NoConversion

object NoConversion {
  import scala.language.implicitConversions

  implicit def toNoConversion[T](x: T): T @@ NoConversion = tag[NoConversion](x)

def foo(x: BigDecimal @@ NoConversion) = println(x)


BigDecimal in last expression marked as red although it compiles correctly.


1 comment
Comment actions Permalink

I created an issue:

Best regards,
Alexander Podkhalyuzin.


Please sign in to leave a comment.