Skip to content

Commit ad309fa

Browse files
committed
Fix #9518: Instantiate HKTypeLambda and replace AppliedType with appliedTo
1 parent 9294593 commit ad309fa

File tree

9 files changed

+42
-13
lines changed

9 files changed

+42
-13
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,9 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
12241224
def Type_select(self: Type)(sym: Symbol)(using Context): Type =
12251225
self.select(sym)
12261226

1227+
def Type_appliedTo(self: Type)(targs: List[TypeOrBounds]): Type =
1228+
self.appliedTo(targs)
1229+
12271230
type ConstantType = Types.ConstantType
12281231

12291232
def ConstantType_TypeTest(using Context): TypeTest[TypeOrBounds, ConstantType] = new {
@@ -1335,8 +1338,6 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13351338
def AppliedType_tycon(self: AppliedType)(using Context): Type = self.tycon
13361339
def AppliedType_args(self: AppliedType)(using Context): List[TypeOrBounds] = self.args
13371340

1338-
def AppliedType_apply(tycon: Type, args: List[TypeOrBounds])(using Context): AppliedType = Types.AppliedType(tycon, args)
1339-
13401341
type AnnotatedType = Types.AnnotatedType
13411342

13421343
def AnnotatedType_TypeTest(using Context): TypeTest[TypeOrBounds, AnnotatedType] = new {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ trait CompilerInterface extends scala.tasty.reflect.Types {
604604
/** The type <this . sym>, reduced if possible */
605605
def Type_select(self: Type)(sym: Symbol)(using ctx: Context): Type
606606

607+
/** The current type applied to given type arguments: `this[targ0, ..., targN]` */
608+
def Type_appliedTo(self: Type)(targs: List[TypeOrBounds]): Type
609+
607610
def ConstantType_TypeTest(using ctx: Context): TypeTest[TypeOrBounds, ConstantType]
608611

609612
def ConstantType_apply(const : Constant)(using ctx : Context) : ConstantType
@@ -644,8 +647,6 @@ trait CompilerInterface extends scala.tasty.reflect.Types {
644647
def AppliedType_tycon(self: AppliedType)(using ctx: Context): Type
645648
def AppliedType_args(self: AppliedType)(using ctx: Context): List[TypeOrBounds]
646649

647-
def AppliedType_apply(tycon: Type, args: List[TypeOrBounds])(using ctx: Context) : AppliedType
648-
649650
def AnnotatedType_TypeTest(using ctx: Context): TypeTest[TypeOrBounds, AnnotatedType]
650651

651652
def AnnotatedType_apply(underlying: Type, annot: Term)(using ctx: Context): AnnotatedType

library/src/scala/tasty/Reflection.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,13 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
14621462

14631463
/** The type <this . sym>, reduced if possible */
14641464
def select(sym: Symbol)(using ctx: Context): Type = reflectSelf.Type_select(self)(sym)
1465+
1466+
/** The current type applied to given type arguments: `this[targ]` */
1467+
def appliedTo(targ: TypeOrBounds): Type = reflectSelf.Type_appliedTo(self)(List(targ))
1468+
1469+
/** The current type applied to given type arguments: `this[targ0, ..., targN]` */
1470+
def appliedTo(targs: List[TypeOrBounds]): Type = reflectSelf.Type_appliedTo(self)(targs)
1471+
14651472
end extension
14661473
end Type
14671474

@@ -1549,14 +1556,12 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
15491556
given AppliedTypeOps as AppliedType.type = AppliedType
15501557

15511558
object AppliedType:
1552-
def apply(tycon: Type, args: List[TypeOrBounds])(using ctx: Context): AppliedType =
1553-
reflectSelf.AppliedType_apply(tycon, args)
1554-
def unapply(x: AppliedType)(using ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] =
1559+
def unapply(x: AppliedType)(using ctx: Context): Option[(Type, List[TypeOrBounds])] =
15551560
Some((x.tycon, x.args))
15561561

15571562
extension (self: AppliedType):
15581563
def tycon(using ctx: Context): Type = reflectSelf.AppliedType_tycon(self)
1559-
def args(using ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] = reflectSelf.AppliedType_args(self)
1564+
def args(using ctx: Context): List[TypeOrBounds] = reflectSelf.AppliedType_args(self)
15601565
end extension
15611566
end AppliedType
15621567

tests/pos-macros/i9251/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object Async {
2828
case AppliedType(tp,tparams1) =>
2929
val fType = summon[quoted.Type[F]]
3030
val ptp = tparams1.tail.head
31-
val ptpTree = Inferred(AppliedType(fType.unseal.tpe,List(ptp)))
31+
val ptpTree = Inferred(fType.unseal.tpe.appliedTo(ptp))
3232
'{ println(${Expr(ptpTree.show)}) }
3333

3434
}

tests/pos-macros/i9518/Macro_1.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
import scala.quoted._
3+
4+
trait CB[T]
5+
6+
inline def shift : Unit = ${ shiftTerm }
7+
8+
def shiftTerm(using QuoteContext): Expr[Unit] = {
9+
import qctx.tasty._
10+
val nTree = '{ ??? : CB[Int] }.unseal
11+
val tp1 = '[CB[Int]].unseal.tpe
12+
val tp2 = '[([X] =>> CB[X])[Int]].unseal.tpe
13+
val ta = '[[X] =>> CB[X]]
14+
val tp3 = '[ta.T[Int]].unseal.tpe
15+
val tp4 = '[CB].unseal.tpe.appliedTo(typeOf[Int])
16+
assert(nTree.tpe <:< tp1)
17+
assert(nTree.tpe <:< tp2)
18+
assert(nTree.tpe <:< tp3)
19+
assert(nTree.tpe <:< tp4)
20+
'{}
21+
}

tests/pos-macros/i9518/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test: Unit = shift

tests/run-macros/tasty-construct-types/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object Macros {
2727
typeOf[RefineMe],
2828
"T",
2929
TypeBounds(typeOf[Int], typeOf[Int]))
30-
val x6T = AppliedType(Type(classOf[List[_]]), List(typeOf[Int]))
30+
val x6T = Type(classOf[List[_]]).appliedTo(List(typeOf[Int]))
3131
val x7T = AnnotatedType(ConstantType(Constant(7)), '{ new TestAnnotation }.unseal)
3232
val x8T =
3333
MatchType(
@@ -37,7 +37,7 @@ object Macros {
3737
TypeLambda(
3838
List("t"),
3939
_ => List(TypeBounds(typeOf[Nothing], typeOf[Any])),
40-
tl => AppliedType(MatchCaseType, List(AppliedType(Type(classOf[List[_]]), List(tl.param(0))), tl.param(0)))))
40+
tl => MatchCaseType.appliedTo(List(Type(classOf[List[_]]).appliedTo(tl.param(0)), tl.param(0)))))
4141
)
4242

4343
assert(x1T =:= '[1].unseal.tpe)

0 commit comments

Comments
 (0)