Skip to content

Commit ee40b81

Browse files
committed
Fix quote report code example
Also update the se of `Expr.summon` Fixes #10308
1 parent a42fe92 commit ee40b81

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,12 @@ extension (inline sc: StringContext)
742742
inline def showMe(inline args: Any*): String = ${ showMeExpr('sc, 'args) }
743743

744744
private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[String] =
745+
import quotes.reflect.report
745746
argsExpr match
746747
case Varargs(argExprs) =>
747748
val argShowedExprs = argExprs.map {
748749
case '{ $arg: tp } =>
749-
val showTp = Type.of[Show[tp]]
750-
Expr.summon(using showTp) match
750+
Expr.summon[Show[tp]] match
751751
case Some(showExpr) =>
752752
'{ $showExpr.show($arg) }
753753
case None =>

tests/run-macros/string-context-implicits/Macro_1.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,24 @@ import scala.quoted._
33

44
extension (sc: StringContext) inline def showMe(inline args: Any*): String = ${ showMeExpr('sc, 'args) }
55

6-
private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[String] = {
6+
private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[String] =
77
import quotes.reflect.report
8-
argsExpr match {
8+
argsExpr match
99
case Varargs(argExprs) =>
1010
val argShowedExprs = argExprs.map {
1111
case '{ $arg: tp } =>
12-
val showTp = Type.of[Show[tp]]
13-
Expr.summon(using showTp) match {
14-
case Some(showExpr) => '{ $showExpr.show($arg) }
15-
case None => report.error(s"could not find implicit for ${Type.show[Show[tp]]}", arg); '{???}
16-
}
12+
Expr.summon[Show[tp]] match
13+
case Some(showExpr) =>
14+
'{ $showExpr.show($arg) }
15+
case None =>
16+
report.error(s"could not find implicit for ${Type.show[Show[tp]]}", arg); '{???}
1717
}
1818
val newArgsExpr = Varargs(argShowedExprs)
1919
'{ $sc.s($newArgsExpr: _*) }
2020
case _ =>
2121
// `new StringContext(...).showMeExpr(args: _*)` not an explicit `showMeExpr"..."`
2222
report.error(s"Args must be explicit", argsExpr)
23-
'{???}
24-
}
25-
}
23+
'{ ??? }
2624

2725
trait Show[-T] {
2826
def show(x: T): String

0 commit comments

Comments
 (0)