Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jeffmay opened this issue Sep 1, 2021 · 1 comment · Fixed by #180
Closed

Comments

@jeffmay
Copy link

jeffmay commented Sep 1, 2021

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.

@To-om
Copy link
Contributor

To-om commented Sep 1, 2021

I'm not sure it is the same case but I also get this warning message with the following example (with macwire 2.4.1):

import com.softwaremill.macwire._

class ClassA()
class ClassB(val a: ClassA)

class Module1 {
  def doSomething(): Unit = ()
  lazy val a: ClassA = wire[ClassA]
}

class Module2(m1: Module1) {
  import m1._
  lazy val b: ClassB = wire[ClassB]
}

@adamw adamw closed this as completed in #180 Oct 6, 2021
adamw added a commit that referenced this issue Oct 6, 2021
#177 Fix auto-application deprecation warning when module is imported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants