Good code red - implicit conversion
Hi,
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.
Code:
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)
foo(BigDecimal(1.1))
~~~~~~~~~~~~
BigDecimal in last expression marked as red although it compiles correctly.
Thanks,
Jon
Please sign in to leave a comment.
I created an issue: http://youtrack.jetbrains.com/issue/SCL-7475
Best regards,
Alexander Podkhalyuzin.