Skip to content

Commit 0d2c851

Browse files
committed
Rename method that takes a Class into a Type
We require this type representation to be able to lift and handle generic arrays. This is not a method that should be used often.
1 parent ae5f1c2 commit 0d2c851

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

compiler/src/dotty/tools/dotc/quoted/reflect/ReflectionCompilerInterface.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
11281128
case _ => None
11291129
}
11301130

1131-
def Type_apply(clazz: Class[?])(using Context): Type =
1131+
def Type_ofErasedClass(clazz: Class[?])(using Context): Type =
11321132
if (clazz.isPrimitive)
11331133
if (clazz == classOf[Boolean]) defn.BooleanType
11341134
else if (clazz == classOf[Byte]) defn.ByteType
@@ -1140,10 +1140,10 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
11401140
else if (clazz == classOf[Double]) defn.DoubleType
11411141
else defn.UnitType
11421142
else if (clazz.isArray)
1143-
defn.ArrayType.appliedTo(Type_apply(clazz.getComponentType))
1143+
defn.ArrayType.appliedTo(Type_ofErasedClass(clazz.getComponentType))
11441144
else if (clazz.isMemberClass) {
11451145
val name = clazz.getSimpleName.toTypeName
1146-
val enclosing = Type_apply(clazz.getEnclosingClass)
1146+
val enclosing = Type_ofErasedClass(clazz.getEnclosingClass)
11471147
if (enclosing.member(name).exists) enclosing.select(name)
11481148
else
11491149
enclosing.classSymbol.companionModule.termRef.select(name)

library/src-bootstrapped/scala/quoted/Liftable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ object Liftable {
6060
given ClassLiftable[T] as Liftable[Class[T]] = new Liftable[Class[T]] {
6161
def toExpr(x: Class[T]) = qctx ?=> {
6262
import qctx.tasty._
63-
Ref(defn.Predef_classOf).appliedToType(Type(x)).seal.asInstanceOf[Expr[Class[T]]]
63+
Ref(defn.Predef_classOf).appliedToType(Type.ofErasedClass(x)).seal.asInstanceOf[Expr[Class[T]]]
6464
}
6565
}
6666

library/src/scala/internal/tasty/CompilerInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ trait CompilerInterface extends scala.tasty.reflect.Types {
512512

513513
def Type_TypeTest(using ctx: Context): TypeTest[Type, Type]
514514

515-
def Type_apply(clazz: Class[_])(using ctx: Context): Type
515+
def Type_ofErasedClass(clazz: Class[_])(using ctx: Context): Type
516516

517517
/** Is `self` type the same as `that` type?
518518
* This is the case iff `Type_isSubType(self, that)` and `Type_isSubType(that, self)`.

library/src/scala/tasty/Reflection.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,13 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
13531353
def of[T <: AnyKind](using qtype: scala.quoted.Type[T], ctx: Context): Type =
13541354
qtype.asInstanceOf[scala.internal.quoted.Type[TypeTree]].typeTree.tpe
13551355

1356-
def apply(clazz: Class[_])(using ctx: Context): Type =
1357-
reflectSelf.Type_apply(clazz)
1356+
/** Returns the type of the runtime class. This type is the erased representation
1357+
* that of the type that is used by arrays.
1358+
*
1359+
* See `Type.of` to get the true type.
1360+
*/
1361+
def ofErasedClass(clazz: Class[_])(using ctx: Context): Type =
1362+
reflectSelf.Type_ofErasedClass(clazz)
13581363
end Type
13591364

13601365
given TypeOps as AnyRef:

0 commit comments

Comments
 (0)