Skip to content

Commit 8913374

Browse files
Merge pull request #9796 from dotty-staging/homogenize-reflect-type-api
Homogenize Reflect Type constructors
2 parents 89af58f + 3560062 commit 8913374

File tree

21 files changed

+72
-73
lines changed

21 files changed

+72
-73
lines changed

library/src-bootstrapped/dotty/internal/StringContextMacro.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ object StringContextMacro {
586586
*/
587587
def checkTypeWithArgs(argument : (Type, Int), conversionChar : Char, partIndex : Int, flags : List[(Char, Int)]) = {
588588
val booleans = List(defn.BooleanType, defn.NullType)
589-
val dates = List(defn.LongType, typeOf[java.util.Calendar], typeOf[java.util.Date])
590-
val floatingPoints = List(defn.DoubleType, defn.FloatType, typeOf[java.math.BigDecimal])
591-
val integral = List(defn.IntType, defn.LongType, defn.ShortType, defn.ByteType, typeOf[java.math.BigInteger])
589+
val dates = List(defn.LongType, Type.of[java.util.Calendar], Type.of[java.util.Date])
590+
val floatingPoints = List(defn.DoubleType, defn.FloatType, Type.of[java.math.BigDecimal])
591+
val integral = List(defn.IntType, defn.LongType, defn.ShortType, defn.ByteType, Type.of[java.math.BigInteger])
592592
val character = List(defn.CharType, defn.ByteType, defn.ShortType, defn.IntType)
593593

594594
val (argType, argIndex) = argument
@@ -597,9 +597,9 @@ object StringContextMacro {
597597
case 'd' | 'o' | 'x' | 'X' => {
598598
checkSubtype(argType, "Int", argIndex, integral : _*)
599599
if (conversionChar != 'd') {
600-
val notAllowedFlagOnCondition = List(('+', !(argType <:< typeOf[java.math.BigInteger]), "only use '+' for BigInt conversions to o, x, X"),
601-
(' ', !(argType <:< typeOf[java.math.BigInteger]), "only use ' ' for BigInt conversions to o, x, X"),
602-
('(', !(argType <:< typeOf[java.math.BigInteger]), "only use '(' for BigInt conversions to o, x, X"),
600+
val notAllowedFlagOnCondition = List(('+', !(argType <:< Type.of[java.math.BigInteger]), "only use '+' for BigInt conversions to o, x, X"),
601+
(' ', !(argType <:< Type.of[java.math.BigInteger]), "only use ' ' for BigInt conversions to o, x, X"),
602+
('(', !(argType <:< Type.of[java.math.BigInteger]), "only use '(' for BigInt conversions to o, x, X"),
603603
(',', true, "',' only allowed for d conversion of integral types"))
604604
checkFlags(partIndex, flags, notAllowedFlagOnCondition : _*)
605605
}
@@ -608,7 +608,7 @@ object StringContextMacro {
608608
case 't' | 'T' => checkSubtype(argType, "Date", argIndex, dates : _*)
609609
case 'b' | 'B' => checkSubtype(argType, "Boolean", argIndex, booleans : _*)
610610
case 'h' | 'H' | 'S' | 's' =>
611-
if (!(argType <:< typeOf[java.util.Formattable]))
611+
if (!(argType <:< Type.of[java.util.Formattable]))
612612
for {flag <- flags ; if (flag._1 == '#')}
613613
reporter.argError("type mismatch;\n found : " + argType.widen.show.stripPrefix("scala.Predef.").stripPrefix("java.lang.").stripPrefix("scala.") + "\n required: java.util.Formattable", argIndex)
614614
case 'n' | '%' =>

library/src-bootstrapped/scala/quoted/util/ExprMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ trait ExprMap {
6363
case Typed(expr, tpt) =>
6464
val tp = tpt.tpe match
6565
case AppliedType(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "<repeated>"), List(tp0: Type)) =>
66-
Type(classOf[Seq[_]]).appliedTo(tp0)
66+
Type.of[Seq].appliedTo(tp0)
6767
case tp => tp
6868
Typed.copy(tree)(transformTerm(expr, tp), transformTypeTree(tpt))
6969
case tree: NamedArg =>

library/src/scala/tasty/Reflection.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,17 +1343,16 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
13431343
// TYPES //
13441344
///////////////
13451345

1346-
/** Returns the type (Type) of T */
1347-
def typeOf[T](using qtype: scala.quoted.Type[T], ctx: Context): Type =
1348-
qtype.asInstanceOf[scala.internal.quoted.Type[T]].typeTree.asInstanceOf[TypeTree].tpe
1349-
1350-
13511346
// ----- Types ----------------------------------------------------
13521347

13531348
given (using ctx: Context) as TypeTest[Type, Type] = reflectSelf.Type_TypeTest
13541349

13551350
object Type:
13561351

1352+
/** Returns the type or kind (Type) of T */
1353+
def of[T <: AnyKind](using qtype: scala.quoted.Type[T], ctx: Context): Type =
1354+
qtype.asInstanceOf[scala.internal.quoted.Type[TypeTree]].typeTree.tpe
1355+
13571356
def apply(clazz: Class[_])(using ctx: Context): Type =
13581357
reflectSelf.Type_apply(clazz)
13591358
end Type
@@ -1643,7 +1642,7 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
16431642
end extension
16441643
end MatchTypeOps
16451644

1646-
1645+
// TODO remove this definition from here
16471646
/**
16481647
* An accessor for `scala.internal.MatchCase[_,_]`, the representation of a `MatchType` case.
16491648
*/

library/src/scala/tasty/reflect/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ trait Types {
292292
/** Pattern representing `X | Y | ...` alternatives. */
293293
type Alternatives <: Tree
294294

295-
/** A type */
295+
/** A type, type constructors, type bounds or NoPrefix */
296296
type Type
297297

298298
/** A singleton type representing a known constant value */

tests/neg-macros/i7919.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
import qctx.tasty._
66
given typeT as quoted.Type[T] // error
77
val tTypeTree = typeT.unseal
8-
val tt = typeOf[T]
8+
val tt = Type.of[T]
99
'{ "in staged" }
1010
}
1111

0 commit comments

Comments
 (0)