Skip to content

Scala 2.13.6 reports that "Auto-application to () s deprecated" when using loan pattern #177

@jeffmay

Description

@jeffmay

In order to inject loggers into my classes with the appropriate class name, I use this handy trick:

import org.slf4j.Logger

import scala.reflect.{classTag, ClassTag}

trait LoggerVendor {
  def getLogger(cls: Class[_]): Logger
  def withLogger[T : ClassTag](build: Logger => T): T = {
    val logger = getLogger(classTag[T].runtimeClass)
    build(logger)
  }
}

class MyService(logger: Logger) {
  def doSomething(): Unit = {
    logger.info("Hello")
  }
}

import com.softwaremill.macwire._

class MyModule(loggerVendor: LoggerVendor) {

  lazy val myService: MyService = loggerVendor.withLogger { _ =>
    wire[MyService]
  }
}

However, when I upgraded to Scala 2.13, I started seeing that the loggerVendor.withLogger{_ => wire[MyService]} causes the following compiler warning:

[warn] ... Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method validateOrThrow,
[warn] or remove the empty argument list from its definition (Java-defined methods are exempt).
[warn] In Scala 3, an unapplied method like this will be eta-expanded into a function.

This was the initial reason for #174, but it appears that there was another bug related to this that was fixed instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions