Skip to content

Commit 59603af

Browse files
committed
fixes #436
1 parent a6e2c8b commit 59603af

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala

+21-10
Original file line numberDiff line numberDiff line change
@@ -261,30 +261,41 @@ private[scalalogging] object LoggerMacro {
261261
case _ => (message, Seq.empty)
262262
}
263263
}
264-
def formatArgs(args: Expr[Seq[Any]])(using q: Quotes): Seq[Expr[AnyRef]] = {
264+
265+
def formatArgs(args: Expr[Seq[Any]])(using q: Quotes
266+
267+
):
268+
Seq[Expr[AnyRef]] = {
265269
import quotes.reflect.*
266270
import util.*
267-
// we recursively obtain the actual value of inline parameters
268-
def map(term:Term) = {
271+
// we recursively obtain the actual value of inline parameters
272+
def map(term: Term) = {
269273
term match {
270274
case t if t.tpe <:< TypeRepr.of[AnyRef] => t.asExprOf[AnyRef]
271-
case t => '{${t.asExpr}.asInstanceOf[AnyRef]}
275+
case t => '{
276+
${
277+
t.asExpr
278+
}.asInstanceOf[AnyRef]
279+
}
272280
}
273281
}
282+
274283
def rec(tree: Term): Option[Seq[Expr[AnyRef]]] = tree match {
275284
case Repeated(elems, _) => Some(elems.map(map))
276285
case Block(Nil, e) => rec(e)
286+
case tped@Typed(Ident(_), _) =>
287+
tped.symbol.tree match {
288+
case ValDef(_, _, Some(rhs)) => rec(rhs)
289+
case _ => None
290+
}
277291
case Typed(e, _) => rec(e)
278292
case Inlined(_, Nil, e) => rec(e)
279-
// Seq():_*, List():_* , forceVarargs(1,2):_*e.g.,
280-
case Apply(TypeApply(_, _), List(Typed(Repeated(elems, _),_))) =>
293+
case Apply(TypeApply(_, _), List(Typed(Repeated(elems, _), _))) =>
281294
Some(elems.map(map))
282-
case Ident(name) =>
283-
// todo
284-
None
285-
case _ =>
295+
case _ =>
286296
None
287297
}
298+
288299
rec(args.asTerm).getOrElse(Seq.empty)
289300
}
290301
}

src/test/scala-3/com/typesafe/scalalogging/Scala3LoggerSpec.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ class Scala3LoggerSpec extends AnyWordSpec with Matchers with Varargs with Mocki
3535
verify(underlying).info("""Hello {}""", arg5ref)
3636
}
3737

38-
"work when passing a inline value as repeated arguments" in {
38+
"work when passing a val as repeated arguments" in {
39+
val f = fixture(_.isInfoEnabled, isEnabled = true)
40+
import f._
41+
val argss = Seq(arg5ref, arg5ref, arg5ref)
42+
logger.info("""Hello {} {} {}""", argss:_*)
43+
verify(underlying).info("""Hello {} {} {}""", Seq(arg5ref, arg5ref, arg5ref):_*)
44+
}
45+
46+
"work when passing a inline def as repeated arguments" in {
3947
val f = fixture(_.isInfoEnabled, isEnabled = true)
4048
import f._
4149
inline def argss = Seq(arg5ref, arg5ref, arg5ref)

0 commit comments

Comments
 (0)