Skip to content

Commit 87e6159

Browse files
authored
Merge pull request #609 from scala/backport-lts-3.3-24018
Backport "Make typeArgs in QuotesImpl work for AnnotatedTypes" to 3.3 LTS
2 parents e0a32a3 + 2eaf15a commit 87e6159

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
18291829

18301830
def typeArgs: List[TypeRepr] = self match
18311831
case AppliedType(_, args) => args
1832+
case AnnotatedType(parent, _) => parent.typeArgs
18321833
case _ => List.empty
18331834
end extension
18341835
end TypeReprMethods

tests/neg-macros/i23008.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
| Exception occurred while executing macro expansion.
66
| java.lang.IllegalArgumentException: requirement failed: value of StringConstant cannot be `null`
77
| at scala.Predef$.require(Predef.scala:337)
8+
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2424)
89
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2423)
9-
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2422)
1010
| at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:80)
1111
| at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:78)
1212
| at scala.quoted.Expr$.apply(Expr.scala:70)

tests/new/test.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object e:
2+
def foldRL(f: Int => Int)(g: String => Int) = ???
3+
4+
5+
val xs = e.foldRL(i => i + 1)(s => s.length)
6+
7+

tests/run-macros/i24006/Eval.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import scala.quoted._
3+
4+
object Eval:
5+
6+
inline def eval[T](x: List[T]) = ${ evalImpl[T]('x) }
7+
def evalImpl[A](x: Expr[List[A]])(using Quotes): Expr[Unit] =
8+
import quotes.reflect.*
9+
println(x.asTerm.tpe.widen)
10+
x.asTerm.tpe.widen.typeArgs.head
11+
'{()}

tests/run-macros/i24006/Test.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Eval.eval
2+
3+
@main def Test() = eval(List(1) :+ 4)

0 commit comments

Comments
 (0)