Skip to content

Commit 477c7a7

Browse files
committed
Fix #7898: Handle annotation without symbols
1 parent 2ed4df9 commit 477c7a7

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

library/src/scala/tasty/reflect/SourceCodePrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig
12281228

12291229
def printAnnotation(annot: Term)(given elideThis: Option[Symbol]): Buffer = {
12301230
val Annotation(ref, args) = annot
1231-
if (annot.symbol.owner.fullName == "scala.internal.quoted.showName") this
1231+
if (annot.symbol.exists && annot.symbol.owner.fullName == "scala.internal.quoted.showName") this
12321232
else {
12331233
this += "@"
12341234
printTypeTree(ref)

tests/run-macros/i7898.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scala.List.apply[scala.PartialFunction[scala.Int, scala.Predef.String]]((((x$1: scala.Int) => (x$1: @scala.unchecked) match {
2+
case 1 =>
3+
"x"
4+
}): scala.<repeated>[scala.PartialFunction[scala.Int, scala.Predef.String]]))

tests/run-macros/i7898/Macro_1.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import quoted._
2+
object Main {
3+
4+
def myMacroImpl(body: Expr[_])(given qctx: QuoteContext): Expr[_] = {
5+
import qctx.tasty.{_, given}
6+
val bodyTerm = body.underlyingArgument.unseal
7+
val showed = bodyTerm.show
8+
'{
9+
println(${Expr(showed)})
10+
${bodyTerm.seal}
11+
}
12+
}
13+
14+
inline def myMacro(body: => Any) <: Any = ${
15+
myMacroImpl('body)
16+
}
17+
}

tests/run-macros/i7898/Test_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def main(args: Array[String]) = {
3+
val _ = Main.myMacro(List[PartialFunction[Int, String]] {
4+
case 1 => "x"
5+
})
6+
}
7+
}

0 commit comments

Comments
 (0)