Skip to content

Fix #9518: Instantiate HKTypeLambda in AppliedTypes #9699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,9 @@ class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInte
def Type_select(self: Type)(sym: Symbol)(using Context): Type =
self.select(sym)

def Type_appliedTo(self: Type)(targs: List[TypeOrBounds]): Type =
self.appliedTo(targs)

type ConstantType = Types.ConstantType

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

def AppliedType_apply(tycon: Type, args: List[TypeOrBounds])(using Context): AppliedType = Types.AppliedType(tycon, args)

type AnnotatedType = Types.AnnotatedType

def AnnotatedType_TypeTest(using Context): TypeTest[TypeOrBounds, AnnotatedType] = new {
Expand Down
5 changes: 3 additions & 2 deletions library/src/scala/internal/tasty/CompilerInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ trait CompilerInterface extends scala.tasty.reflect.Types {
/** The type <this . sym>, reduced if possible */
def Type_select(self: Type)(sym: Symbol)(using ctx: Context): Type

/** The current type applied to given type arguments: `this[targ0, ..., targN]` */
def Type_appliedTo(self: Type)(targs: List[TypeOrBounds]): Type

def ConstantType_TypeTest(using ctx: Context): TypeTest[TypeOrBounds, ConstantType]

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

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

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

def AnnotatedType_apply(underlying: Type, annot: Term)(using ctx: Context): AnnotatedType
Expand Down
13 changes: 9 additions & 4 deletions library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,13 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface =>

/** The type <this . sym>, reduced if possible */
def select(sym: Symbol)(using ctx: Context): Type = reflectSelf.Type_select(self)(sym)

/** The current type applied to given type arguments: `this[targ]` */
def appliedTo(targ: TypeOrBounds): Type = reflectSelf.Type_appliedTo(self)(List(targ))

/** The current type applied to given type arguments: `this[targ0, ..., targN]` */
def appliedTo(targs: List[TypeOrBounds]): Type = reflectSelf.Type_appliedTo(self)(targs)

end extension
end Type

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

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

extension (self: AppliedType):
def tycon(using ctx: Context): Type = reflectSelf.AppliedType_tycon(self)
def args(using ctx: Context): List[TypeOrBounds /* Type | TypeBounds */] = reflectSelf.AppliedType_args(self)
def args(using ctx: Context): List[TypeOrBounds] = reflectSelf.AppliedType_args(self)
end extension
end AppliedType

Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i9251/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Async {
case AppliedType(tp,tparams1) =>
val fType = summon[quoted.Type[F]]
val ptp = tparams1.tail.head
val ptpTree = Inferred(AppliedType(fType.unseal.tpe,List(ptp)))
val ptpTree = Inferred(fType.unseal.tpe.appliedTo(ptp))
'{ println(${Expr(ptpTree.show)}) }

}
21 changes: 21 additions & 0 deletions tests/pos-macros/i9518/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import scala.quoted._

trait CB[T]

inline def shift : Unit = ${ shiftTerm }

def shiftTerm(using QuoteContext): Expr[Unit] = {
import qctx.tasty._
val nTree = '{ ??? : CB[Int] }.unseal
val tp1 = '[CB[Int]].unseal.tpe
val tp2 = '[([X] =>> CB[X])[Int]].unseal.tpe
val ta = '[[X] =>> CB[X]]
val tp3 = '[ta.T[Int]].unseal.tpe
val tp4 = '[CB].unseal.tpe.appliedTo(typeOf[Int])
assert(nTree.tpe <:< tp1)
assert(nTree.tpe <:< tp2)
assert(nTree.tpe <:< tp3)
assert(nTree.tpe <:< tp4)
'{}
}
1 change: 1 addition & 0 deletions tests/pos-macros/i9518/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test: Unit = shift
4 changes: 2 additions & 2 deletions tests/run-macros/tasty-construct-types/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Macros {
typeOf[RefineMe],
"T",
TypeBounds(typeOf[Int], typeOf[Int]))
val x6T = AppliedType(Type(classOf[List[_]]), List(typeOf[Int]))
val x6T = Type(classOf[List[_]]).appliedTo(List(typeOf[Int]))
val x7T = AnnotatedType(ConstantType(Constant(7)), '{ new TestAnnotation }.unseal)
val x8T =
MatchType(
Expand All @@ -37,7 +37,7 @@ object Macros {
TypeLambda(
List("t"),
_ => List(TypeBounds(typeOf[Nothing], typeOf[Any])),
tl => AppliedType(MatchCaseType, List(AppliedType(Type(classOf[List[_]]), List(tl.param(0))), tl.param(0)))))
tl => MatchCaseType.appliedTo(List(Type(classOf[List[_]]).appliedTo(tl.param(0)), tl.param(0)))))
)

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