Skip to content

In Scala3, using a non-inline variable-length parameter doesn't print correctly #436

Open
@jxnu-liguobin

Description

@jxnu-liguobin
          FYI in case someone else also runs into this, when using Scala 3 and varargs with `:_*` (or just `*` using Scala 3 syntax) the code compiles with scala-logging 3.9.4 and 3.9.5, but doesn't actually pass the values to the underlying logger. You can check following script with scala-cli:
//> using dep "com.typesafe.scala-logging::scala-logging:3.9.4"
//> using dep "ch.qos.logback:logback-classic:1.5.1"

import com.typesafe.scalalogging.LazyLogging

object Test extends LazyLogging {
  def log(): Unit = {
    val args = Seq("1", "2")
    logger.info("test {} {}", args:_*)
  }
}
Test.log()

when running with --scala-version 2.13.12 it will print "test 1 2" and with --scala-version 3.3.1 just "test {} {}". With scala-logging 3.9.5 it won't compile on 2.13 at all

I think the issue for Scala 3 is in this part of the macro:
https://github.com/lightbend-labs/scala-logging/blob/main/src/main/scala-3/com/typesafe/scalalogging/LoggerMacro.scala#L279

Originally posted by @SakulK in #354 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions