@@ -4,10 +4,11 @@ package reporting
4
4
5
5
import scala .language .unsafeNulls
6
6
7
- import core .Contexts ._
8
- import config .Config
9
- import config .Printers
10
- import core .Mode
7
+ import core .* , Contexts .* , Decorators .*
8
+ import config .*
9
+ import printing .Formatting .*
10
+
11
+ import scala .compiletime .*
11
12
12
13
/** Exposes the {{{ trace("question") { op } }}} syntax.
13
14
*
@@ -51,9 +52,20 @@ trait TraceSyntax:
51
52
else op
52
53
53
54
inline def apply [T ](inline question : String , inline printer : Printers .Printer , inline show : Boolean )(inline op : T )(using Context ): T =
54
- inline if isEnabled then
55
- doTrace[T ](question, printer, if show then showShowable(_) else alwaysToString)(op)
56
- else op
55
+ apply(question, printer, {
56
+ val showOp : T => String = inline if show == true then
57
+ val showT = summonInline[Show [T ]]
58
+ {
59
+ given Show [T ] = showT
60
+ t => i " $t"
61
+ }
62
+ else
63
+ summonFrom {
64
+ case given Show [T ] => t => i " $t"
65
+ case _ => alwaysToString
66
+ }
67
+ showOp
68
+ })(op)
57
69
58
70
inline def apply [T ](inline question : String , inline printer : Printers .Printer )(inline op : T )(using Context ): T =
59
71
apply[T ](question, printer, false )(op)
@@ -64,15 +76,11 @@ trait TraceSyntax:
64
76
inline def apply [T ](inline question : String )(inline op : T )(using Context ): T =
65
77
apply[T ](question, false )(op)
66
78
67
- private def showShowable (x : Any )(using Context ) = x match
68
- case x : printing.Showable => x.show
69
- case _ => String .valueOf(x)
70
-
71
79
private val alwaysToString = (x : Any ) => String .valueOf(x)
72
80
73
81
private def doTrace [T ](question : => String ,
74
82
printer : Printers .Printer = Printers .default,
75
- showOp : T => String = alwaysToString )
83
+ showOp : T => String )
76
84
(op : => T )(using Context ): T =
77
85
if ctx.mode.is(Mode .Printing ) || ! isForced && (printer eq Printers .noPrinter) then op
78
86
else
0 commit comments