File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed
docs/docs/reference/metaprogramming
tests/run-macros/string-context-implicits Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -742,12 +742,12 @@ extension (inline sc: StringContext)
742
742
inline def showMe (inline args : Any * ): String = $ { showMeExpr(' sc , ' args ) }
743
743
744
744
private def showMeExpr (sc : Expr [StringContext ], argsExpr : Expr [Seq [Any ]])(using Quotes ): Expr [String ] =
745
+ import quotes .reflect .report
745
746
argsExpr match
746
747
case Varargs (argExprs) =>
747
748
val argShowedExprs = argExprs.map {
748
749
case ' { $arg : tp } =>
749
- val showTp = Type .of[Show [tp]]
750
- Expr .summon(using showTp) match
750
+ Expr .summon[Show [tp]] match
751
751
case Some (showExpr) =>
752
752
' { $showExpr.show($arg) }
753
753
case None =>
Original file line number Diff line number Diff line change @@ -3,26 +3,24 @@ import scala.quoted._
3
3
4
4
extension (sc : StringContext ) inline def showMe (inline args : Any * ): String = $ { showMeExpr(' sc , ' args ) }
5
5
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 ] =
7
7
import quotes .reflect .report
8
- argsExpr match {
8
+ argsExpr match
9
9
case Varargs (argExprs) =>
10
10
val argShowedExprs = argExprs.map {
11
11
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); ' { ??? }
17
17
}
18
18
val newArgsExpr = Varargs (argShowedExprs)
19
19
' { $sc.s($newArgsExpr : _* ) }
20
20
case _ =>
21
21
// `new StringContext(...).showMeExpr(args: _*)` not an explicit `showMeExpr"..."`
22
22
report.error(s " Args must be explicit " , argsExpr)
23
- ' {??? }
24
- }
25
- }
23
+ ' { ??? }
26
24
27
25
trait Show [- T ] {
28
26
def show (x : T ): String
You can’t perform that action at this time.
0 commit comments