Skip to content

Commit 0717f18

Browse files
committed
Make TypeTestsCasts an Object
No need to use inheritance here.
1 parent e325601 commit 0717f18

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ object Types {
214214
case _ => NoType
215215
}
216216

217-
/** Is this type guaranteed not to have `null` as a value?
218-
* For the moment this is only true for modules, but it could
219-
* be refined later.
220-
*/
217+
/** Is this type guaranteed not to have `null` as a value? */
221218
final def isNotNull(implicit ctx: Context): Boolean = this match {
222219
case tp: ConstantType => tp.value.value != null
223220
case tp: ClassInfo => !tp.cls.isNullableClass && tp.cls != defn.NothingClass

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ class Erasure extends Phase with DenotTransformer { thisTransformer =>
139139
i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree : ${tree.tpe} / ${tree.getClass} is illegal after erasure, phase = ${ctx.phase.prev}")
140140
}
141141

142-
object Erasure extends TypeTestsCasts{
143-
142+
object Erasure {
144143
import tpd._
144+
import TypeTestsCasts._
145145

146146
object Boxing {
147147

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ast.Trees._
77
import Erasure.Boxing._
88
import TypeErasure._
99
import ValueClasses._
10+
import SymUtils._
1011
import core.Flags._
1112
import util.Positions._
1213

@@ -22,7 +23,7 @@ import util.Positions._
2223
* Unfortunately this phase ended up being not Y-checkable unless types are erased. A cast to an ConstantType(3) or x.type
2324
* cannot be rewritten before erasure.
2425
*/
25-
trait TypeTestsCasts {
26+
object TypeTestsCasts {
2627
import ast.tpd._
2728

2829
def interceptTypeApply(tree: TypeApply)(implicit ctx: Context): Tree = ctx.traceIndented(s"transforming ${tree.show}", show = true) {
@@ -157,7 +158,7 @@ trait TypeTestsCasts {
157158
transformIsInstanceOf(expr, erasure(testType), flagUnrelated)
158159
}
159160

160-
if ((sym eq defn.Any_isInstanceOf) || (sym eq defn.Any_typeTest))
161+
if (sym.isTypeTest)
161162
transformTypeTest(expr, tree.args.head.tpe, flagUnrelated = true)
162163
else if (sym eq defn.Any_asInstanceOf)
163164
transformAsInstanceOf(erasure(tree.args.head.tpe))

0 commit comments

Comments
 (0)