akka / akka-http

The Streaming-first HTTP server/module of Akka
https://doc.akka.io/libraries/akka-http/current/
Other
1.34k stars 594 forks source link

Compiler warning for headerValueByType since Scala 2.12.2 #1095

Open hseeberger opened 7 years ago

hseeberger commented 7 years ago
[warn] .../LastEventIdSpec.scala:45: Adaptation of argument list by inserting () is deprecated: this is unlikely to be what you want.
[warn]         signature: HeaderDirectives.headerValueByType[T](magnet: akka.http.scaladsl.server.directives.HeaderMagnet[T]): akka.http.scaladsl.server.Directive1[T]
[warn]   given arguments: <none>
[warn]  after adaptation: HeaderDirectives.headerValueByType((): Unit)
[warn]     headerValueByType[`Last-Event-ID`]() { case `Last-Event-ID`(id) => complete(id.toString) }
[warn]                                       ^
[warn] one warning found
jrudolph commented 7 years ago

Not sure what we can do about those ones. We know since a while that these kinds of usages are prone to compiler warnings but we haven't found a solution so far.

The problem applies to all magnet usages that work with empty argument lists.

ktoso commented 7 years ago

Yeah too bad we can't silence it on specific cases :( There's no way around it that I know of sadly, since the () is needed there otherwise we would not be able to have the { ... right after it (scala would think the code block was attempting to "be" the magnet).

jrudolph commented 7 years ago

For this particular case we might come up with an alternative syntax which uses headerValueByType(HeaderCompanion) and deprecate the old magnet-y one.

ktoso commented 7 years ago

Hm that looks good actually indeed 👍

hseeberger commented 7 years ago

Yeah, get rid of all that magnetism if possible ;-)

spangaer commented 6 years ago

For those on a quest for a warning free copy-paste.

Option 1, efficient but mysterious:

optionalHeaderValueByType[Host](()) {
  ???
}

Option 2, inspired by @jrudolph comments for future strategy:


/**
 *  https://github.com/akka/akka-http/issues/1095
 */
object Magnets {
  val HostHeader = HeaderMagnet.fromUnitNormalHeader[Host]((): Unit)
}
optionalHeaderValueByType(Magnets.HostHeader) {
  ???
}
AaronDelaplane commented 6 years ago
Success(akka.Done) takes care of the problem.