开发者

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

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

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

What does the line "&开发者_如何学JAVAlt;notype > <: ThingManager?" mean?

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


-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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜