TypeTestsCasts
This transform normalizes type tests and type casts, also replacing type tests with singleton argument type with reference equality check Any remaining type tests
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.
Value members
Concrete methods
Whether (x:X).isInstanceOf[P] can be checked at runtime?
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
Then check:
- if
X <:< P, TRUE - if
Pis a singleton type, TRUE - if
Prefers to an abstract type member or type parameter, FALSE - if
P = Array[T], checkable(E, T) whereEis the element type ofX, defaults toAny. - if
Pispre.F[Ts]andpre.Frefers to a class which is notArray: (a) replaceTswith fresh type variablesXs(b) constrainXswithpre.F[Xs] <:< X(c) maximizepre.F[Xs]and checkpre.F[Xs] <:< P - if
P = T1 | T2orP = T1 & T2, checkable(X, T1) && checkable(X, T2). - if
Pis a refinement type, FALSE - otherwise, TRUE