E123: Type Test Always Diverges
This warning is emitted when a type test (via isInstanceOf or pattern matching) is performed on a scrutinee whose type cannot contain any value, meaning the test can never return a result.
This typically occurs when the scrutinee has type Nothing, such as expressions like ???, throw, or values explicitly typed as Nothing. Since Nothing has no instances, the type test will never complete - evaluating the scrutinee will always diverge before the test can be performed.
Example
def example: Boolean = ???.isInstanceOf[String]
Error
-- [E123] Syntax Warning: example.scala:1:39 -----------------------------------
1 |def example: Boolean = ???.isInstanceOf[String]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|This type test will never return a result since the scrutinee type (??? : => Nothing) does not contain any value.
Solution
// Use a type that can contain values
def example(x: Any): Boolean = x.isInstanceOf[String]
// Or acknowledge that the code path is unreachable
def example: Boolean = ??? // Returns Nothing, no type test needed
In this article