Skip to content

Commit fe1b3ae

Browse files
committed
Fix #9518: Instantiate HKTypeLambda in AppliedTypes
1 parent 5ee8777 commit fe1b3ae

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,10 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
13351335
def AppliedType_tycon(self: AppliedType)(using Context): Type = self.tycon
13361336
def AppliedType_args(self: AppliedType)(using Context): List[TypeOrBounds] = self.args
13371337

1338-
def AppliedType_apply(tycon: Type, args: List[TypeOrBounds])(using Context): AppliedType = Types.AppliedType(tycon, args)
1338+
def AppliedType_apply(tycon: Type, args: List[TypeOrBounds])(using Context): Type =
1339+
tycon match
1340+
case tycon: Types.HKTypeLambda => tycon.instantiate(args)
1341+
case _ => Types.AppliedType(tycon, args)
13391342

13401343
type AnnotatedType = Types.AnnotatedType
13411344

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ trait CompilerInterface extends scala.tasty.reflect.Types {
644644
def AppliedType_tycon(self: AppliedType)(using ctx: Context): Type
645645
def AppliedType_args(self: AppliedType)(using ctx: Context): List[TypeOrBounds]
646646

647-
def AppliedType_apply(tycon: Type, args: List[TypeOrBounds])(using ctx: Context) : AppliedType
647+
def AppliedType_apply(tycon: Type, args: List[TypeOrBounds])(using ctx: Context) : Type
648648

649649
def AnnotatedType_TypeTest(using ctx: Context): TypeTest[TypeOrBounds, AnnotatedType]
650650

library/src/scala/tasty/Reflection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>
15491549
given AppliedTypeOps as AppliedType.type = AppliedType
15501550

15511551
object AppliedType:
1552-
def apply(tycon: Type, args: List[TypeOrBounds])(using ctx: Context): AppliedType =
1552+
def apply(tycon: Type, args: List[TypeOrBounds])(using ctx: Context): Type =
15531553
reflectSelf.AppliedType_apply(tycon, args)
15541554
def unapply(x: AppliedType)(using ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] =
15551555
Some((x.tycon, x.args))

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 = AppliedType('[CB].unseal.tpe, List(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

0 commit comments

Comments
 (0)