Skip to content

Commit 07fae04

Browse files
Merge pull request #9798 from dotty-staging/rename-reflection-classof-type
Rename reflection `Class[?]` to `Type` conversion
2 parents cbedf64 + c9de0e1 commit 07fae04

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ object Liftable {
5858

5959
/** Default liftable for Class[T] */
6060
given ClassLiftable[T] as Liftable[Class[T]] = new Liftable[Class[T]] {
61-
def toExpr(x: Class[T]) = qctx ?=> {
62-
import qctx.tasty._
63-
Ref(defn.Predef_classOf).appliedToType(Type(x)).seal.asInstanceOf[Expr[Class[T]]]
61+
def toExpr(x: Class[T]) = {
62+
val qctx1 = scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface(qctx)
63+
import qctx1.tasty._
64+
val tpe = qctx1.tasty.Type_ofErasedClass(x)
65+
Ref(defn.Predef_classOf).appliedToType(tpe).seal.asInstanceOf[Expr[Class[T]]]
6466
}
6567
}
6668

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,11 @@ 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+
/** Returns the type of the runtime class. This type is the erased representation
516+
* that of the type that is used by arrays.
517+
*
518+
*/
519+
def Type_ofErasedClass(clazz: Class[_])(using ctx: Context): Type
516520

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

library/src/scala/tasty/Reflection.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,6 @@ 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)
13581356
end Type
13591357

13601358
given TypeOps as AnyRef:

0 commit comments

Comments
 (0)