Skip to content

Commit b962805

Browse files
committed
Remove Reflection.LambdaType
This can be encoded with intersection types in the few places where it is relevant
1 parent 9b9c9f8 commit b962805

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,13 +1895,14 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
18951895
end ParamRefTypeTest
18961896

18971897
object ParamRef extends ParamRefModule:
1898-
def unapply(x: ParamRef): Option[(LambdaType, Int)] =
1899-
Some((x.binder, x.paramNum))
1898+
def unapply(x: ParamRef): Option[(MethodType | PolyType | TypeLambda, Int)] =
1899+
Some((x.binder.asInstanceOf[MethodType | PolyType | TypeLambda], x.paramNum))
19001900
end ParamRef
19011901

19021902
object ParamRefMethodsImpl extends ParamRefMethods:
19031903
extension (self: ParamRef):
1904-
def binder: LambdaType = self.binder.asInstanceOf[LambdaType] // Cast to tpd
1904+
def binder: MethodType | PolyType | TypeLambda =
1905+
self.binder.asInstanceOf[MethodType | PolyType | TypeLambda]
19051906
def paramNum: Int = self.paramNum
19061907
end extension
19071908
end ParamRefMethodsImpl
@@ -1967,8 +1968,6 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
19671968
end extension
19681969
end RecursiveTypeMethodsImpl
19691970

1970-
type LambdaType = dotc.core.Types.LambdaType
1971-
19721971
type MethodType = dotc.core.Types.MethodType
19731972

19741973
object MethodTypeTypeTest extends TypeTest[Type, MethodType]:

library/src/scala/tasty/Reflection.scala

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ import scala.tasty.reflect._
9191
* +- ThisType
9292
* +- RecursiveThis
9393
* +- RecursiveType
94-
* +- LambdaType -+- MethodType
95-
* | +- PolyType
96-
* | +- TypeLambda
94+
* +- MethodType
95+
* +- PolyType
96+
* +- TypeLambda
9797
* +- TypeBounds
9898
* +- NoPrefix
9999
*
@@ -2122,15 +2122,15 @@ trait Reflection { reflection =>
21222122
val ParamRef: ParamRefModule
21232123

21242124
trait ParamRefModule { this: ParamRef.type =>
2125-
def unapply(x: ParamRef): Option[(LambdaType, Int)]
2125+
def unapply(x: ParamRef): Option[(MethodType | PolyType | TypeLambda, Int)]
21262126
}
21272127

21282128
given ParamRefMethods as ParamRefMethods = ParamRefMethodsImpl
21292129
protected val ParamRefMethodsImpl: ParamRefMethods
21302130

21312131
trait ParamRefMethods:
21322132
extension (self: ParamRef):
2133-
def binder: LambdaType
2133+
def binder: MethodType | PolyType | TypeLambda
21342134
def paramNum: Int
21352135
end extension
21362136
end ParamRefMethods
@@ -2210,12 +2210,8 @@ trait Reflection { reflection =>
22102210
end extension
22112211
end RecursiveTypeMethods
22122212

2213-
// TODO: remove LambdaType and use union types (MethodType | PolyType | TypeLambda)
2214-
/** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */
2215-
type LambdaType <: Type
2216-
22172213
/** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */
2218-
type MethodType <: LambdaType
2214+
type MethodType <: Type
22192215

22202216
given TypeTest[Type, MethodType] = MethodTypeTypeTest
22212217
protected val MethodTypeTypeTest: TypeTest[Type, MethodType]
@@ -2242,7 +2238,7 @@ trait Reflection { reflection =>
22422238
end MethodTypeMethods
22432239

22442240
/** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */
2245-
type PolyType <: LambdaType
2241+
type PolyType <: Type
22462242

22472243
given TypeTest[Type, PolyType] = PolyTypeTypeTest
22482244
protected val PolyTypeTypeTest: TypeTest[Type, PolyType]
@@ -2267,7 +2263,7 @@ trait Reflection { reflection =>
22672263
end PolyTypeMethods
22682264

22692265
/** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */
2270-
type TypeLambda <: LambdaType
2266+
type TypeLambda <: Type
22712267

22722268
given TypeTest[Type, TypeLambda] = TypeLambdaTypeTest
22732269
protected val TypeLambdaTypeTest: TypeTest[Type, TypeLambda]

library/src/scala/tasty/reflect/SourceCodePrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
11791179
printType(body)
11801180

11811181
case ParamRef(lambda, idx) =>
1182-
lambda match {
1182+
(lambda: @unchecked) match {
11831183
case MethodType(params, _, _) => this += params(idx)
11841184
case PolyType(params, _, _) => this += params(idx)
11851185
case TypeLambda(params, _, _) => this += params(idx)

0 commit comments

Comments
 (0)