Pergunta

Does anyone have some experience dealing with these types of compilation errors?

case class BasicAuthRequest[A](account: Account, request: Request[A]) extends WrappedRequest(request) {
    def asOpt[T](implicit fjs: Reads[T]): Option[T] = {
        catching(classOf[RuntimeException]).opt(fjs.reads(JsNull)).filter {
        case JsUndefined(_) => false
        case _ => true
    } }
}

I get this response from the scala compiler when attempting to compile this playframework method

[error]  found   : play.api.libs.json.JsUndefined
[error]  required: play.api.libs.json.JsResult[?T1] where type ?T1 <: T (this is a GADT skolem)
[error]         case JsUndefined(_) => false
[error]              ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 23 s, completed Nov 27, 2012 3:01:20 AM
Foi útil?

Solução

fjs.reads(JsNull) returns JsResult[T] which is then wrapped into Option by opt

so there are couple of issues with this code:

  • return type should be Option[JsResult[T]]
  • JsUndefined is not a subclass of JsResult, so you can't use it in match
  • compiler error message is cryptic indeed, would you mind submitting an issue to scala tracker?

here is the code I think you were trying to implement

  case class Account()

  case class BasicAuthRequest[A](account: Account, request: Request[A]) extends WrappedRequest(request) {
    def asOpt[T](implicit fjs: Reads[T]): Option[T] =
      scala.util.control.Exception.catching(classOf[RuntimeException]).opt(fjs.reads(JsNull)).flatMap(_.asOpt)
  }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top