0

I've implemented my first Play 2.1 Controller based on an example from the Play Framework doc site at http://www.playframework.com/documentation/2.1.1/ScalaJsonRequests . The operative part of my code looks like:

object Sessions extends Controller {
  val log = LoggerFactory.getLogger(getClass())

  implicit val rds = (
    (__ \ 'userName).read[String] and
    (__ \ 'credentials).read[String]) tupled

  def session = Action(parse.json) { request =>
    log.trace("session request: {}", request)
    request.body.validate[(String, String)].map {
      case (userName, credentials) =>
        if (isAuthenticated(userName, credentials)) {
          Created(createSession(userName))
        } else {
          log.warn("userName: {} failed isAuthenticated", userName)
          BadRequest
        }
    }.recoverTotal {
      e =>
        val message = "Parse error: " + JsError.toFlatJson(e)
        log.warn(message)
        BadRequest
    }
  }

The problem is that the Scala compiler warns on the "tupled" thing (is that a keyword, operator, I don't know...I'm new to this). I don't know whether the warning is real and I should take the recommended action or not. The text of the warn is

[warn] /Users/bobk/work/dm2-server/app/controllers/admin/Sessions.scala:20: postfix operator tupled should be enabled
[warn] by making the implicit value language.postfixOps visible.
[warn] This can be achieved by adding the import clause 'import scala.language.postfixOps'
[warn] or by setting the compiler option -language:postfixOps.
[warn] See the Scala docs for value scala.language.postfixOps for a discussion
[warn] why the feature should be explicitly enabled.
[warn]     (__ \ 'credentials).read[String]) tupled
[warn]                                       ^
[warn] one warning found

Searching ScalaDocs for the discussion on "scala.language.postfixOps" turns up nothing; I couldn't find the discussion. What does this warning mean? Should I take the recommended action to make it go away?

I have much to learn about Scala and Play.

Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115

1 Answers1

2

These types of warnings show up when you are using more advanced features. SIP 18: Modularizing Language Features explains it in more detail.

In your case you could do this:

(__ \ 'credentials).read[String]).tupled

I would recommend making sure you do not have any warnings in your code. The way you want to solve these types of warnings is up to you. I usually import the feature.

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
  • Yep. That's what I did to make the bad man go away. I'm not so sure all of these "advanced features" in Scala are worth the confusion this language places on those new to it. In any event, thanks. – Bob Kuhar May 25 '13 at 17:19