scala type src and val src
While working on Scala, I noticed a definition:
type ??? = Nothing
as seems it’s used this way
def myMethod = ??? //TODO
But, if I change this to
type ??? = Nothing
type ^^^ = Nothing
def myMethod = ^^^ //TODO
It actually fails compilation right on this line. Why?
Test 1
Remove type ??? = Nothing
, then many other places fail compilation. The line is effective
Test 2
Try to trace impl of ??? present at def myMethod = ??? //TODO
, found in predef:
/** `???` can be used for marking methods that remain to be implemented.
* @throws NotImplementedError
*/
def ??? : Nothing = throw new NotImplementedError
Now it’s clear. The line I’ve been seeing defines a type ??? aliasing Nothing type. The val ??? is defined in predef and therefore auto-imported. If I look closer, I would’ve noticed that the errors from removing type ??? = Nothing
doesn’t include def myMethod = ??? //TODO
Scala compiler is smart enough to tell, always, whether a type or a value is used