Skip to content

Commit 02536cd

Browse files
committed
Handle splices within annotated types
1 parent a5a3127 commit 02536cd

File tree

7 files changed

+37
-1
lines changed

7 files changed

+37
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
136136
case tp: ThisType =>
137137
assert(checkSymLevel(tp.cls, tp, pos).isEmpty)
138138
mapOver(tp)
139+
case tp: AnnotatedType =>
140+
derivedAnnotatedType(tp, apply(tp.parent), tp.annot)
139141
case _ =>
140142
mapOver(tp)
141143
}

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Pickler extends Phase {
7878
pickled.iterator.grouped(10).toList.zipWithIndex.map {
7979
case (row, i) => s"${i}0: ${row.mkString(" ")}"
8080
}
81-
81+
8282
// println(i"rawBytes = \n$rawBytes%\n%") // DEBUG
8383
if (pickling ne noPrinter) {
8484
println(i"**** pickled info of $cls")

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class ReifyQuotes extends MacroTransform {
157157
val tagDef = tagDefCache.getOrElseUpdate(prefix.symbol, mkTagSymbolAndAssignType(prefix))
158158
tagDef.symbol.typeRef
159159
}
160+
case AnnotatedType(parent, _) =>
161+
apply(parent) // Only keep the Annotated tree
160162
case _ =>
161163
mapOver(tp)
162164
}

tests/pos/i7519b.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted._
2+
import scala.annotation.StaticAnnotation
3+
4+
class Annot(in: Int) extends StaticAnnotation
5+
6+
class Quoted[T]
7+
8+
inline def quote[T]: Quoted[T] = ${ quoteImpl[T] }
9+
10+
def quoteImpl[T: Type](given qctx: QuoteContext): Expr[Quoted[T]] = {
11+
val value: Expr[Int] = '{ 42 }
12+
'{ new Quoted[T @Annot($value)] }
13+
}

tests/run-macros/i7519c.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
new Quoted[scala.Int @Annot(42)]()

tests/run-macros/i7519c/Macro_1.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted._
2+
import scala.annotation.StaticAnnotation
3+
4+
class Annot(in: Int) extends StaticAnnotation
5+
6+
class Quoted[T]
7+
8+
inline def quote[T]: String = ${ quoteImpl[T] }
9+
10+
def quoteImpl[T: Type](given qctx: QuoteContext): Expr[String] = {
11+
val value: Expr[Int] = '{ 42 }
12+
Expr(('{ new Quoted[T @Annot($value)] }).show)
13+
}

tests/run-macros/i7519c/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
println(quote[Int])
4+
}
5+
}

0 commit comments

Comments
 (0)