Skip to content

Commit 0f757c5

Browse files
Merge pull request #9706 from dotty-staging/remove-reflect-TypeOrBounds
Remove Reflection.TypeOrBounds abstraction
2 parents 5ea8694 + 6872bdb commit 0f757c5

File tree

17 files changed

+265
-296
lines changed

17 files changed

+265
-296
lines changed

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

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
10161016
case _ => None
10171017
}
10181018

1019-
def WildcardTypeTree_tpe(self: WildcardTypeTree)(using Context): TypeOrBounds = self.tpe.stripTypeVar
1019+
def WildcardTypeTree_tpe(self: WildcardTypeTree)(using Context): Type = self.tpe.stripTypeVar
10201020

10211021
type CaseDef = tpd.CaseDef
10221022

@@ -1118,34 +1118,9 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
11181118
// TYPES //
11191119
/////////////
11201120

1121-
type TypeOrBounds = Types.Type
1122-
1123-
type NoPrefix = Types.NoPrefix.type
1124-
1125-
def NoPrefix_TypeTest(using Context): TypeTest[TypeOrBounds, NoPrefix] = new {
1126-
def runtimeClass: Class[?] = classOf[Types.NoPrefix.type]
1127-
override def unapply(x: Any): Option[NoPrefix] =
1128-
if (x == Types.NoPrefix) Some(Types.NoPrefix) else None
1129-
}
1130-
1131-
type TypeBounds = Types.TypeBounds
1132-
1133-
def TypeBounds_TypeTest(using Context): TypeTest[TypeOrBounds, TypeBounds] = new {
1134-
def runtimeClass: Class[?] = classOf[TypeBounds]
1135-
override def unapply(x: Any): Option[TypeBounds] = x match
1136-
case x: Types.TypeBounds => Some(x)
1137-
case _ => None
1138-
}
1139-
1140-
def TypeBounds_apply(low: Type, hi: Type)(using Context): TypeBounds =
1141-
Types.TypeBounds(low, hi)
1142-
1143-
def TypeBounds_low(self: TypeBounds)(using Context): Type = self.lo
1144-
def TypeBounds_hi(self: TypeBounds)(using Context): Type = self.hi
1145-
11461121
type Type = Types.Type
11471122

1148-
def Type_TypeTest(using Context): TypeTest[TypeOrBounds, Type] = new {
1123+
def Type_TypeTest(using Context): TypeTest[Type, Type] = new {
11491124
def runtimeClass: Class[?] = classOf[Type]
11501125
override def unapply(x: Any): Option[Type] = x match
11511126
case x: TypeBounds => None
@@ -1225,12 +1200,12 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12251200
def Type_select(self: Type)(sym: Symbol)(using Context): Type =
12261201
self.select(sym)
12271202

1228-
def Type_appliedTo(self: Type)(targs: List[TypeOrBounds]): Type =
1203+
def Type_appliedTo(self: Type)(targs: List[Type]): Type =
12291204
self.appliedTo(targs)
12301205

12311206
type ConstantType = Types.ConstantType
12321207

1233-
def ConstantType_TypeTest(using Context): TypeTest[TypeOrBounds, ConstantType] = new {
1208+
def ConstantType_TypeTest(using Context): TypeTest[Type, ConstantType] = new {
12341209
def runtimeClass: Class[?] = classOf[ConstantType]
12351210
override def unapply(x: Any): Option[ConstantType] = x match
12361211
case tpe: Types.ConstantType => Some(tpe)
@@ -1244,30 +1219,30 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12441219

12451220
type TermRef = Types.NamedType
12461221

1247-
def TermRef_TypeTest(using Context): TypeTest[TypeOrBounds, TermRef] = new {
1222+
def TermRef_TypeTest(using Context): TypeTest[Type, TermRef] = new {
12481223
def runtimeClass: Class[?] = classOf[TermRef]
12491224
override def unapply(x: Any): Option[TermRef] = x match
12501225
case tp: Types.TermRef => Some(tp)
12511226
case _ => None
12521227
}
12531228

1254-
def TermRef_apply(qual: TypeOrBounds, name: String)(using Context): TermRef =
1229+
def TermRef_apply(qual: Type, name: String)(using Context): TermRef =
12551230
Types.TermRef(qual, name.toTermName)
12561231

1257-
def TermRef_qualifier(self: TermRef)(using Context): TypeOrBounds = self.prefix
1232+
def TermRef_qualifier(self: TermRef)(using Context): Type = self.prefix
12581233

12591234
def TermRef_name(self: TermRef)(using Context): String = self.name.toString
12601235

12611236
type TypeRef = Types.NamedType
12621237

1263-
def TypeRef_TypeTest(using Context): TypeTest[TypeOrBounds, TypeRef] = new {
1238+
def TypeRef_TypeTest(using Context): TypeTest[Type, TypeRef] = new {
12641239
def runtimeClass: Class[?] = classOf[TypeRef]
12651240
override def unapply(x: Any): Option[TypeRef] = x match
12661241
case tp: Types.TypeRef => Some(tp)
12671242
case _ => None
12681243
}
12691244

1270-
def TypeRef_qualifier(self: TypeRef)(using Context): TypeOrBounds = self.prefix
1245+
def TypeRef_qualifier(self: TypeRef)(using Context): Type = self.prefix
12711246

12721247
def TypeRef_name(self: TypeRef)(using Context): String = self.name.toString
12731248

@@ -1277,7 +1252,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12771252

12781253
type NamedTermRef = Types.NamedType
12791254

1280-
def NamedTermRef_TypeTest(using Context): TypeTest[TypeOrBounds, NamedTermRef] = new {
1255+
def NamedTermRef_TypeTest(using Context): TypeTest[Type, NamedTermRef] = new {
12811256
def runtimeClass: Class[?] = classOf[NamedTermRef]
12821257
override def unapply(x: Any): Option[NamedTermRef] = x match
12831258
case tpe: Types.NamedType =>
@@ -1289,11 +1264,11 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12891264
}
12901265

12911266
def NamedTermRef_name(self: NamedTermRef)(using Context): String = self.name.toString
1292-
def NamedTermRef_qualifier(self: NamedTermRef)(using Context): TypeOrBounds = self.prefix
1267+
def NamedTermRef_qualifier(self: NamedTermRef)(using Context): Type = self.prefix
12931268

12941269
type SuperType = Types.SuperType
12951270

1296-
def SuperType_TypeTest(using Context): TypeTest[TypeOrBounds, SuperType] = new {
1271+
def SuperType_TypeTest(using Context): TypeTest[Type, SuperType] = new {
12971272
def runtimeClass: Class[?] = classOf[SuperType]
12981273
override def unapply(x: Any): Option[SuperType] = x match
12991274
case tpe: Types.SuperType => Some(tpe)
@@ -1308,14 +1283,14 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13081283

13091284
type Refinement = Types.RefinedType
13101285

1311-
def Refinement_TypeTest(using Context): TypeTest[TypeOrBounds, Refinement] = new {
1286+
def Refinement_TypeTest(using Context): TypeTest[Type, Refinement] = new {
13121287
def runtimeClass: Class[?] = classOf[Refinement]
13131288
override def unapply(x: Any): Option[Refinement] = x match
13141289
case tpe: Types.RefinedType => Some(tpe)
13151290
case _ => None
13161291
}
13171292

1318-
def Refinement_apply(parent: Type, name: String, info: TypeOrBounds /* Type | TypeBounds */)(using Context): Refinement = {
1293+
def Refinement_apply(parent: Type, name: String, info: Type)(using Context): Refinement = {
13191294
val name1 =
13201295
info match
13211296
case _: TypeBounds => name.toTypeName
@@ -1325,23 +1300,23 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13251300

13261301
def Refinement_parent(self: Refinement)(using Context): Type = self.parent
13271302
def Refinement_name(self: Refinement)(using Context): String = self.refinedName.toString
1328-
def Refinement_info(self: Refinement)(using Context): TypeOrBounds = self.refinedInfo
1303+
def Refinement_info(self: Refinement)(using Context): Type = self.refinedInfo
13291304

13301305
type AppliedType = Types.AppliedType
13311306

1332-
def AppliedType_TypeTest(using Context): TypeTest[TypeOrBounds, AppliedType] = new {
1307+
def AppliedType_TypeTest(using Context): TypeTest[Type, AppliedType] = new {
13331308
def runtimeClass: Class[?] = classOf[AppliedType]
13341309
override def unapply(x: Any): Option[AppliedType] = x match
13351310
case tpe: Types.AppliedType => Some(tpe)
13361311
case _ => None
13371312
}
13381313

13391314
def AppliedType_tycon(self: AppliedType)(using Context): Type = self.tycon
1340-
def AppliedType_args(self: AppliedType)(using Context): List[TypeOrBounds] = self.args
1315+
def AppliedType_args(self: AppliedType)(using Context): List[Type] = self.args
13411316

13421317
type AnnotatedType = Types.AnnotatedType
13431318

1344-
def AnnotatedType_TypeTest(using Context): TypeTest[TypeOrBounds, AnnotatedType] = new {
1319+
def AnnotatedType_TypeTest(using Context): TypeTest[Type, AnnotatedType] = new {
13451320
def runtimeClass: Class[?] = classOf[AnnotatedType]
13461321
override def unapply(x: Any): Option[AnnotatedType] = x match
13471322
case tpe: Types.AnnotatedType => Some(tpe)
@@ -1356,7 +1331,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13561331

13571332
type AndType = Types.AndType
13581333

1359-
def AndType_TypeTest(using Context): TypeTest[TypeOrBounds, AndType] = new {
1334+
def AndType_TypeTest(using Context): TypeTest[Type, AndType] = new {
13601335
def runtimeClass: Class[?] = classOf[AndType]
13611336
override def unapply(x: Any): Option[AndType] = x match
13621337
case tpe: Types.AndType => Some(tpe)
@@ -1371,7 +1346,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13711346

13721347
type OrType = Types.OrType
13731348

1374-
def OrType_TypeTest(using Context): TypeTest[TypeOrBounds, OrType] = new {
1349+
def OrType_TypeTest(using Context): TypeTest[Type, OrType] = new {
13751350
def runtimeClass: Class[?] = classOf[OrType]
13761351
override def unapply(x: Any): Option[OrType] = x match
13771352
case tpe: Types.OrType => Some(tpe)
@@ -1386,7 +1361,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13861361

13871362
type MatchType = Types.MatchType
13881363

1389-
def MatchType_TypeTest(using Context): TypeTest[TypeOrBounds, MatchType] = new {
1364+
def MatchType_TypeTest(using Context): TypeTest[Type, MatchType] = new {
13901365
def runtimeClass: Class[?] = classOf[MatchType]
13911366
override def unapply(x: Any): Option[MatchType] = x match
13921367
case tpe: Types.MatchType => Some(tpe)
@@ -1402,7 +1377,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14021377

14031378
type ByNameType = Types.ExprType
14041379

1405-
def ByNameType_TypeTest(using Context): TypeTest[TypeOrBounds, ByNameType] = new {
1380+
def ByNameType_TypeTest(using Context): TypeTest[Type, ByNameType] = new {
14061381
def runtimeClass: Class[?] = classOf[ByNameType]
14071382
override def unapply(x: Any): Option[ByNameType] = x match
14081383
case tpe: Types.ExprType => Some(tpe)
@@ -1415,21 +1390,21 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14151390

14161391
type ParamRef = Types.ParamRef
14171392

1418-
def ParamRef_TypeTest(using Context): TypeTest[TypeOrBounds, ParamRef] = new {
1393+
def ParamRef_TypeTest(using Context): TypeTest[Type, ParamRef] = new {
14191394
def runtimeClass: Class[?] = classOf[ParamRef]
14201395
override def unapply(x: Any): Option[ParamRef] = x match
14211396
case tpe: Types.TypeParamRef => Some(tpe)
14221397
case tpe: Types.TermParamRef => Some(tpe)
14231398
case _ => None
14241399
}
14251400

1426-
def ParamRef_binder(self: ParamRef)(using Context): LambdaType[TypeOrBounds] =
1427-
self.binder.asInstanceOf[LambdaType[TypeOrBounds]] // Cast to tpd
1401+
def ParamRef_binder(self: ParamRef)(using Context): LambdaType =
1402+
self.binder.asInstanceOf[LambdaType] // Cast to tpd
14281403
def ParamRef_paramNum(self: ParamRef)(using Context): Int = self.paramNum
14291404

14301405
type ThisType = Types.ThisType
14311406

1432-
def ThisType_TypeTest(using Context): TypeTest[TypeOrBounds, ThisType] = new {
1407+
def ThisType_TypeTest(using Context): TypeTest[Type, ThisType] = new {
14331408
def runtimeClass: Class[?] = classOf[ThisType]
14341409
override def unapply(x: Any): Option[ThisType] = x match
14351410
case tpe: Types.ThisType => Some(tpe)
@@ -1440,7 +1415,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14401415

14411416
type RecursiveThis = Types.RecThis
14421417

1443-
def RecursiveThis_TypeTest(using Context): TypeTest[TypeOrBounds, RecursiveThis] = new {
1418+
def RecursiveThis_TypeTest(using Context): TypeTest[Type, RecursiveThis] = new {
14441419
def runtimeClass: Class[?] = classOf[RecursiveThis]
14451420
override def unapply(x: Any): Option[RecursiveThis] = x match
14461421
case tpe: Types.RecThis => Some(tpe)
@@ -1451,7 +1426,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14511426

14521427
type RecursiveType = Types.RecType
14531428

1454-
def RecursiveType_TypeTest(using Context): TypeTest[TypeOrBounds, RecursiveType] = new {
1429+
def RecursiveType_TypeTest(using Context): TypeTest[Type, RecursiveType] = new {
14551430
def runtimeClass: Class[?] = classOf[RecursiveType]
14561431
override def unapply(x: Any): Option[RecursiveType] = x match
14571432
case tpe: Types.RecType => Some(tpe)
@@ -1465,11 +1440,11 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14651440

14661441
def RecursiveThis_recThis(self: RecursiveType)(using Context): RecursiveThis = self.recThis
14671442

1468-
type LambdaType[ParamInfo] = Types.LambdaType { type PInfo = ParamInfo }
1443+
type LambdaType = Types.LambdaType
14691444

14701445
type MethodType = Types.MethodType
14711446

1472-
def MethodType_TypeTest(using Context): TypeTest[TypeOrBounds, MethodType] = new {
1447+
def MethodType_TypeTest(using Context): TypeTest[Type, MethodType] = new {
14731448
def runtimeClass: Class[?] = classOf[MethodType]
14741449
override def unapply(x: Any): Option[MethodType] = x match
14751450
case tpe: Types.MethodType => Some(tpe)
@@ -1488,7 +1463,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
14881463

14891464
type PolyType = Types.PolyType
14901465

1491-
def PolyType_TypeTest(using Context): TypeTest[TypeOrBounds, PolyType] = new {
1466+
def PolyType_TypeTest(using Context): TypeTest[Type, PolyType] = new {
14921467
def runtimeClass: Class[?] = classOf[PolyType]
14931468
override def unapply(x: Any): Option[PolyType] = x match
14941469
case tpe: Types.PolyType => Some(tpe)
@@ -1505,7 +1480,7 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
15051480

15061481
type TypeLambda = Types.TypeLambda
15071482

1508-
def TypeLambda_TypeTest(using Context): TypeTest[TypeOrBounds, TypeLambda] = new {
1483+
def TypeLambda_TypeTest(using Context): TypeTest[Type, TypeLambda] = new {
15091484
def runtimeClass: Class[?] = classOf[TypeLambda]
15101485
override def unapply(x: Any): Option[TypeLambda] = x match
15111486
case tpe: Types.TypeLambda => Some(tpe)
@@ -1521,6 +1496,28 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
15211496
self.newParamRef(idx)
15221497
def TypeLambda_resType(self: TypeLambda)(using Context): Type = self.resType
15231498

1499+
type NoPrefix = Types.NoPrefix.type
1500+
1501+
def NoPrefix_TypeTest(using Context): TypeTest[Type, NoPrefix] = new {
1502+
def runtimeClass: Class[?] = classOf[Types.NoPrefix.type]
1503+
override def unapply(x: Any): Option[NoPrefix] =
1504+
if (x == Types.NoPrefix) Some(Types.NoPrefix) else None
1505+
}
1506+
1507+
type TypeBounds = Types.TypeBounds
1508+
1509+
def TypeBounds_TypeTest(using Context): TypeTest[Type, TypeBounds] = new {
1510+
def runtimeClass: Class[?] = classOf[TypeBounds]
1511+
override def unapply(x: Any): Option[TypeBounds] = x match
1512+
case x: Types.TypeBounds => Some(x)
1513+
case _ => None
1514+
}
1515+
1516+
def TypeBounds_apply(low: Type, hi: Type)(using Context): TypeBounds =
1517+
Types.TypeBounds(low, hi)
1518+
1519+
def TypeBounds_low(self: TypeBounds)(using Context): Type = self.lo
1520+
def TypeBounds_hi(self: TypeBounds)(using Context): Type = self.hi
15241521

15251522
//////////////////////
15261523
// IMPORT SELECTORS //

0 commit comments

Comments
 (0)