Skip to content

Commit

Permalink
Merge pull request #12186 from mkurz/scala2.13.12_compat
Browse files Browse the repository at this point in the history
[2.8.x] Better Scala 2.13.12 compatibility
  • Loading branch information
mkurz committed Nov 8, 2023
2 parents 983ecab + 2b057cd commit 82c4756
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class Routes(
case include: Include => {prefixed_@(dep.ident)_@(index).router.documentation}
},}
Nil
).foldLeft(List.empty[(String,String,String)]) { (s,e) => e.asInstanceOf[Any] match {
case r @@ (_,_,_) => s :+ r.asInstanceOf[(String,String,String)]
case l => s ++ l.asInstanceOf[List[(String,String,String)]]
).foldLeft(Seq.empty[(String, String, String)]) { (s,e) => e.asInstanceOf[Any] match {
case r @@ (_,_,_) => s :+ r.asInstanceOf[(String, String, String)]
case l => s ++ l.asInstanceOf[List[(String, String, String)]]
}}

@for((dep, index) <- rules.zipWithIndex){@dep.rule match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class ConfiguredActor private (
import ConfiguredActor._

val config = configuration.get[String]("my.config")
def onMessage(msg: GetConfig) = {
def onMessage(msg: GetConfig): ConfiguredActor = {
msg.replyTo ! config
this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class HelloActor private (
) extends AbstractBehavior(context) {
import HelloActor._

def onMessage(msg: SayHello) = {
def onMessage(msg: SayHello): HelloActor = {
msg.replyTo ! s"Hello, ${msg.name}"
this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CustomAkkaHttpServer(context: AkkaHttpServer.Context) extends AkkaHttpServ

/** A factory that instantiates a CustomAkkaHttpServer. */
class CustomAkkaHttpServerProvider extends ServerProvider {
def createServer(context: ServerProvider.Context) = {
def createServer(context: ServerProvider.Context): CustomAkkaHttpServer = {
val serverContext = AkkaHttpServer.Context.fromServerProviderContext(context)
new CustomAkkaHttpServer(serverContext)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import javaguide.testhelpers.MockJavaAction

import play.core.j.JavaHandlerComponents
import play.mvc.Http
import play.mvc.Result

class JavaRouting extends Specification {
"the java router" should {
Expand Down Expand Up @@ -71,7 +72,7 @@ class JavaRouting extends Specification {
"Location",
call(
new MockJavaAction(app.injector.instanceOf[JavaHandlerComponents]) {
override def invocation(req: Http.Request) =
override def invocation(req: Http.Request): CompletableFuture[Result] =
CompletableFuture.completedFuture(new javaguide.http.routing.controllers.Application().index())
},
FakeRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ScalaAkkaEmbeddingPlay extends Specification with WsTestClient {
}
}

override lazy val httpErrorHandler = new DefaultHttpErrorHandler(
override lazy val httpErrorHandler: DefaultHttpErrorHandler = new DefaultHttpErrorHandler(
environment,
configuration,
devContext.map(_.sourceMapper),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ScalaNettyEmbeddingPlay extends Specification with WsTestClient {
}
}

override lazy val httpErrorHandler =
override lazy val httpErrorHandler: DefaultHttpErrorHandler =
new DefaultHttpErrorHandler(environment, configuration, devContext.map(_.sourceMapper), Some(router)) {
protected override def onNotFound(request: RequestHeader, message: String) = {
Future.successful(Results.NotFound("Nothing was found!"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class MyCode {
}

class MyModule extends play.api.inject.Module {
def bindings(environment: Environment, configuration: Configuration) = {
def bindings(environment: Environment, configuration: Configuration): Seq[play.api.inject.Binding[_]] = {
Seq(bind[MyCode].toInstance(new MyCode))
}
}
// #module-definition

// #builtin-module-definition
class MyI18nModule extends play.api.inject.Module {
def bindings(environment: Environment, configuration: Configuration) = {
def bindings(environment: Environment, configuration: Configuration): Seq[play.api.inject.Binding[_]] = {
Seq(
bind[Langs].toProvider[DefaultLangsProvider],
bind[MessagesApi].toProvider[MyMessagesApiProvider]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import play.api.mvc._
import scala.concurrent.ExecutionContext

class LoggingFilter @Inject() (implicit ec: ExecutionContext) extends EssentialFilter with Logging {
def apply(nextFilter: EssentialAction) = new EssentialAction {
def apply(nextFilter: EssentialAction): EssentialAction = new EssentialAction {
def apply(requestHeader: RequestHeader) = {
val startTime = System.currentTimeMillis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ package httpfilters {

object router {
class Routes extends play.api.routing.Router {
def routes = ???
def documentation = ???
def withPrefix(prefix: String) = ???
def routes: Nothing = ???
def documentation: Nothing = ???
def withPrefix(prefix: String): Nothing = ???
}
}

Expand All @@ -73,7 +73,7 @@ package httpfilters {
// gzipFilter is defined in GzipFilterComponents
override lazy val httpFilters = Seq(gzipFilter, loggingFilter)

lazy val router = new Routes( /* ... */ )
lazy val router: Routes = new Routes( /* ... */ )
}

//#components-filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ScalaWebSockets extends PlaySpecification {
def close() = closed.success(true)
}
class MyActor extends Actor {
def receive = PartialFunction.empty
def receive: PartialFunction[Any, Nothing] = PartialFunction.empty

// #actor-post-stop
override def postStop() = {
Expand All @@ -80,7 +80,7 @@ class ScalaWebSockets extends PlaySpecification {

"allow closing the WebSocket" in new WithApplication() {
class MyActor extends Actor {
def receive = PartialFunction.empty
def receive: PartialFunction[Any, Nothing] = PartialFunction.empty

// #actor-stop
import akka.actor.PoisonPill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ package routers {
lazy val barRoutes = new bar.Routes(httpErrorHandler)
lazy val applicationController = new controllers.Application(controllerComponents)

lazy val router = new Routes(httpErrorHandler, applicationController, barRoutes, assets)
lazy val router: Routes = new Routes(httpErrorHandler, applicationController, barRoutes, assets)
}
//#routers
}
Expand All @@ -136,7 +136,7 @@ package controllers {
}

trait AssetsComponents extends _root_.controllers.AssetsComponents {
override lazy val assets = new controllers.Assets(httpErrorHandler, assetsMetadata)
override lazy val assets: controllers.Assets = new controllers.Assets(httpErrorHandler, assetsMetadata)
}

class Assets(errorHandler: HttpErrorHandler, assetsMetadata: AssetsMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ package playmodule {
import play.api.inject._

class HelloModule extends Module {
def bindings(environment: Environment, configuration: Configuration) = Seq(
def bindings(environment: Environment, configuration: Configuration): Seq[play.api.inject.Binding[_]] = Seq(
bind[Hello].qualifiedWith("en").to[EnglishHello],
bind[Hello].qualifiedWith("de").to[GermanHello]
)
Expand All @@ -235,7 +235,7 @@ package eagerplaymodule {
import play.api.inject._

class HelloModule extends Module {
def bindings(environment: Environment, configuration: Configuration) = Seq(
def bindings(environment: Environment, configuration: Configuration): Seq[play.api.inject.Binding[_]] = Seq(
bind[Hello].qualifiedWith("en").to[EnglishHello].eagerly(),
bind[Hello].qualifiedWith("de").to[GermanHello].eagerly()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ package scalaguide.forms.scalaforms {
import play.api.data.format.Formatter
import play.api.data.format.Formats._
implicit object UrlFormatter extends Formatter[URL] {
override val format = Some(("format.url", Nil))
override val format: Option[(String, Seq[Any])] = Some(("format.url", Nil))
override def bind(key: String, data: Map[String, String]) = parsing(new URL(_), "error.url", Nil)(key, data)
override def unbind(key: String, value: URL) = Map(key -> value.toString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ package scalaguide.http.scalaactionscomposition {
override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = {
block(request)
}
override def composeAction[A](action: Action[A]) = new Logging(action)
override def composeAction[A](action: Action[A]): Logging[A] = new Logging(action)
}
// #actions-wrapping-builder

Expand Down Expand Up @@ -246,7 +246,7 @@ package scalaguide.http.scalaactionscomposition {
// #item-action-builder
def ItemAction(itemId: String)(implicit ec: ExecutionContext) = new ActionRefiner[UserRequest, ItemRequest] {
def executionContext = ec
def refine[A](input: UserRequest[A]) = Future.successful {
def refine[A](input: UserRequest[A]): Future[Either[Status, ItemRequest[A]]] = Future.successful {
ItemDao
.findById(itemId)
.map(new ItemRequest(_, input))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class MockComponent extends Component {
// #component

// #component-module
import play.api.inject.Binding
import play.api.Environment
import play.api.Configuration
import play.api.inject.Module

class ComponentModule extends Module {
def bindings(env: Environment, conf: Configuration) = Seq(
def bindings(env: Environment, conf: Configuration): Seq[Binding[_]] = Seq(
bind[Component].to[DefaultComponent]
)
}
Expand Down

0 comments on commit 82c4756

Please sign in to comment.