Dotty Documentation

0.11.0-bin-SNAPSHOT

object TypeTestsCasts
extends Object

This transform normalizes type tests and type casts, also replacing type tests with singleton argument type with reference equality check Any remaining type tests - use the object methods $isInstanceOf and $asInstanceOf - have a reference type as receiver - can be translated directly to machine instructions

Unfortunately this phase ended up being not Y-checkable unless types are erased. A cast to an ConstantType(3) or x.type cannot be rewritten before erasure. That's why TypeTestsCasts is called from Erasure.

[-] Constructors

[-] Members

[+] def checkable ( X: Type , P: Type , pos: Position ) ( implicit ctx: Context ) : Boolean

Whether (x:X).isInstanceOf[P] can be checked at runtime?

First do the following substitution: (a) replace T @unchecked and pattern binder types (e.g., _$1) in P with WildcardType (b) replace pattern binder types (e.g., _$1) in X: - variance = 1 : hiBound - variance = -1 : loBound - variance = 0 : OrType(Any, Nothing) // TODO: use original type param bounds

Then check:

  1. if X <:< P, TRUE
  2. if P is a singleton type, TRUE
  3. if P refers to an abstract type member or type parameter, FALSE
  4. if P = Array[T], checkable(E, T) where E is the element type of X, defaults to Any.
  5. if P is pre.F[Ts] and pre.F refers to a class which is not Array: (a) replace Ts with fresh type variables Xs (b) constrain Xs with pre.F[Xs] <:< X (c) instantiate Xs and check pre.F[Xs] <:< P
  6. if P = T1 | T2 or P = T1 & T2, checkable(X, T1) && checkable(X, T2).
  7. if P is a refinement type, FALSE
  8. otherwise, TRUE
[+] def interceptTypeApply ( tree: TypeApply ) ( implicit ctx: Context ) : Tree