Skip to content

Commit 66f8213

Browse files
authored
Make typeArgs in QuotesImpl work for AnnotatedTypes (#24018)
Fixes #24006
2 parents 89e316e + 925d749 commit 66f8213

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

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

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

19121912
def typeArgs: List[TypeRepr] = self match
19131913
case AppliedType(_, args) => args
1914+
case AnnotatedType(parent, _) => parent.typeArgs
1915+
case FlexibleType(underlying) => underlying.typeArgs
19141916
case _ => List.empty
19151917
end extension
19161918
end TypeReprMethods

tests/neg-macros/i23008.check

Lines changed: 2 additions & 2 deletions
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:393)
8-
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2540)
9-
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2539)
8+
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2542)
9+
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2541)
1010
| at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:82)
1111
| at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:80)
1212
| at scala.quoted.Expr$.apply(Expr.scala:72)

tests/new/test.scala

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

3-
def test(consume x: Cap) = ???
49

5-
def impl(using consume x: Cap) = ???

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)