Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scalac -explaintypes: What does "<notype> <: X?" mean?

Tags:

scala

If I run "scalac -explaintypes" and see something like:

Nothing <: ThingManager?
  <notype> <: ThingManager?
  false
true

What does the line "<notype > <: ThingManager?" mean?

Does it mean "No type could possibly conform to ThingManager" ?

like image 575
Sebastien Diot Avatar asked Aug 14 '11 09:08

Sebastien Diot


1 Answers

-explain-types traces all calls to subtyping checks. Indentation is used to show recursive calls.

Here's a small example:

scala210 -explaintypes -e '0 : java.lang.String'
scalacmd9062993631372828655.scala:1: error: type mismatch;
 found   : Int(0)
 required: java.lang.String
0 : java.lang.String
^
one error found
Int(0) <: java.lang.String?
  Int <: java.lang.String?
    <notype> <: java.lang.String?
    false
  false
false

There are three levels of recursion. The first call is checking if UniqueConstantType(0) <:< UniqueTypeRef(String). The LHS is is a singleton type for the literal integer. The check continues by considering the underlying type of that singleton type UniqueTypeRef(Int) <:< UniqueTypeRef(String).

The conformance check then searches for the a supertype of Int of the class String (the base type), and then checking if this conforms to String. There is no such supertype, so NoType is returned. The recursive call to <:< leads to the output <notype> <: java.lang.String.

sym2.isClass && {
  val base = tr1 baseType sym2  // UniqueTypeRef(Int) baseType String => NoType
  (base ne tr1) && base <:< tr2
}

NoType is a Null Object. (The compiler also uses this pattern for NoSymbol, NoPosition).

like image 180
retronym Avatar answered Oct 02 '22 12:10

retronym