Skip to content

Commit

Permalink
Fix for varargs
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnu-liguobin committed Mar 1, 2024
1 parent 14db4cb commit a6e2c8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ private[scalalogging] object LoggerMacro {
case Block(Nil, e) => rec(e)
case Typed(e, _) => rec(e)
case Inlined(_, Nil, e) => rec(e)
// Seq():_*, List():_* e.g.,
case Apply(TypeApply(Select(Ident(_), "apply"), _), List(Typed(Repeated(elems, _),_))) =>
// Seq():_*, List():_* , forceVarargs(1,2):_*e.g.,
case Apply(TypeApply(_, _), List(Typed(Repeated(elems, _),_))) =>
Some(elems.map(map))
// forceVarargs(1,2):_*
case Apply(TypeApply(_, _), List(Typed(Repeated(elems, _),_))) => Some(elems.map(map))
case Ident(name) =>
// todo
None
case _ =>
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class Scala3LoggerSpec extends AnyWordSpec with Matchers with Varargs with Mocki
logger.info("""Hello {}""", forceVarargs(arg5ref):_*)
verify(underlying).info("""Hello {}""", arg5ref)
}

"work when passing a inline value as repeated arguments" in {
val f = fixture(_.isInfoEnabled, isEnabled = true)
import f._
inline def argss = Seq(arg5ref, arg5ref, arg5ref)
logger.info("""Hello {} {} {}""", argss:_*)
verify(underlying).info("""Hello {} {} {}""", Seq(arg5ref, arg5ref, arg5ref):_*)
}
}

private def fixture(p: Underlying => Boolean, isEnabled: Boolean) = new LoggerF(p, isEnabled)
Expand Down

0 comments on commit a6e2c8b

Please sign in to comment.