Dotty: Wrong overload resolution on org.slf4j.Logger's method

Created on 28 Feb 2020  路  3Comments  路  Source: lampepfl/dotty

minimized code

  • project/plugins.sbt
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.0")
  • buid.sbt
scalaVersion := "0.22.0-RC1" // compile successfully with "2.13.1"
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.30"
  • src/main/scala/Main.scala
import org.slf4j.{Logger, LoggerFactory}

object Main {
  def main(args: Array[String]): Unit = {
    val logger: Logger = LoggerFactory.getLogger("main")
    logger.error("{}{}{}", 1, 2, 3) // error here
  }
}

Compilation output

[error] -- [E134] Type Mismatch Error: /dotty-example/src/main/scala/Main.scala:6:11 
[error] 6 |    logger.error("{}{}{}", 1, 2, 3) // error here
[error]   |    ^^^^^^^^^^^^
[error]   |None of the overloaded alternatives of method error in trait Logger with types
[error]   | (x$0: org.slf4j.Marker, x$1: String, x$2: Throwable): Unit
[error]   | (x$0: org.slf4j.Marker, x$1: String, x$2: Object*): Unit
[error]   | (x$0: org.slf4j.Marker, x$1: String, x$2: Any, x$3: Any): Unit
[error]   | (x$0: org.slf4j.Marker, x$1: String, x$2: Any): Unit
[error]   | (x$0: org.slf4j.Marker, x$1: String): Unit
[error]   | (x$0: String, x$1: Throwable): Unit
[error]   | (x$0: String, x$1: Object*): Unit
[error]   | (x$0: String, x$1: Any, x$2: Any): Unit
[error]   | (x$0: String, x$1: Any): Unit
[error]   | (x$0: String): Unit
[error]   |match arguments (("{}{}{}" : String), (1 : Int), (2 : Int), (3 : Int))
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

expectation

Compile successfully and choose this method in Logger.java:

public void error(String format, Object... arguments);

Note: Change scalaVersion := "2.13.1" in build.sbt => compile successfully

java bug

All 3 comments

[error] | (x$0: String, x$1: Object*): Unit

This should be Any*.

Maybe fixed in #8718
Related to #8977

https://github.com/lampepfl/dotty/pull/8718 doesn't fix it. I believe #8977 is the same issue as this one, so I'll close this one in favor of #8977 since it doesn't rely on an external library.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dwijnand picture dwijnand  路  3Comments

m-sp picture m-sp  路  3Comments

smarter picture smarter  路  3Comments

andreaTP picture andreaTP  路  3Comments

odersky picture odersky  路  3Comments