Scala apply implicit conversions where not required and make compilation fail with "Type mismatch" error.
Example:
import scala.language.implicitConversions
case class Result(value: String)
implicit def intToResult(v: Int): Result = Result(v.toString)
val res: Result = Some(100).getOrElse(200/*wrong implicit intToResult call*/)
Error:
Error:(7, 46) type mismatch;
found : Any
required: Result
val res: Result = Some(100).getOrElse(200)
The expression Some(100).getOrElse(200)
should return a Int
and scala should convert it into Result
using intToResult
via implicit convertion.
But Scala apply intToResult
implicitly also on getOrElse
's value breaking compile.
IntelliJ doesn't show me any kind of error writing this expression, no syntax highlighting.
Tests:
- Scala 2.11.8
- Scala 2.13.0