Skip to content

Commit 7db4121

Browse files
Merge pull request #14923 from dotty-staging/fix-14740
Add reflect AppliedType constructor
2 parents d8c15c8 + 4f9ef98 commit 7db4121

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
18931893
end AppliedTypeTypeTest
18941894

18951895
object AppliedType extends AppliedTypeModule:
1896+
def apply(tycon: TypeRepr, args: List[TypeRepr]): AppliedType =
1897+
Types.AppliedType(tycon, args)
18961898
def unapply(x: AppliedType): (TypeRepr, List[TypeRepr]) =
18971899
(AppliedTypeMethods.tycon(x), AppliedTypeMethods.args(x))
18981900
end AppliedType

library/src/scala/quoted/Quotes.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
28122812

28132813
/** Methods of the module object `val AppliedType` */
28142814
trait AppliedTypeModule { this: AppliedType.type =>
2815+
/** Applied the type constructor `T` to a list of type arguments `T_1,..,T_n` to create `T[T_1,..,T_n]` */
2816+
@experimental
2817+
def apply(tycon: TypeRepr, args: List[TypeRepr]): AppliedType
28152818
def unapply(x: AppliedType): (TypeRepr, List[TypeRepr])
28162819
}
28172820

project/MiMaFilters.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ object MiMaFilters {
1111
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#SymbolMethods.typeRef"),
1212
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#SymbolMethods.termRef"),
1313
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeTreeModule.ref"),
14+
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#AppliedTypeModule.apply"),
1415

1516
// Experimental `MainAnnotation` APIs. Can be added in 3.3.0 or later.
1617
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation"),

tests/pos-macros/i14740/Macro_1.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted.*
2+
3+
type Foo[T]
4+
5+
transparent inline def emptyList[T]: Any = ${ impl[T] }
6+
7+
private def impl[T: Type](using Quotes): Expr[Any] = {
8+
import quotes.reflect._
9+
val tpe = AppliedType(TypeRepr.of[Foo], List(TypeRepr.of[T])) // test AppliedType constructor
10+
Typed('{???}.asTerm, Inferred(tpe)).asExpr // '{ ??? : Foo[T] }
11+
}

tests/pos-macros/i14740/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test1: Foo[Any] = emptyList[Any]
2+
def test2: Foo[Int] = emptyList[Int]
3+
def test3: Foo[String] = emptyList[String]

0 commit comments

Comments
 (0)