From Play 2.4.2 to 2.5.4: polymorphic expression cannot be instantiated to expected type

116 views
Skip to first unread message

Jon Kleiser

unread,
Jun 13, 2016, 8:01:23 AM6/13/16
to play-framework
Hi,

I'm just migrating a Play project frm 2.4.2 to 2.5.4. The only compiler error I get now, is this:

[error] /Volumes/P2/vib-2.5.4/app/login/Login.scala:139: polymorphic expression cannot be instantiated to expected type;

[error]  found   : [E]play.api.libs.iteratee.Iteratee[E,play.api.mvc.Result]

[error]  required: play.api.libs.streams.Accumulator[akka.util.ByteString,play.api.mvc.Result]

[error]         play.api.libs.iteratee.Done(redirToLogin(request), play.api.libs.iteratee.Input.Empty)


and line 139 is the one with "play.api.libs.iteratee.Done", here:

  def Authenticated[A]()(action: User => EssentialAction): EssentialAction = {

    EssentialAction { request =>
      getLoggedInUser(request).map { userInfo =>
        action(userInfo)(request)
      }.getOrElse {
        play.api.libs.iteratee.Done(redirToLogin(request), play.api.libs.iteratee.Input.Empty)
      }
    }
  }

Can anyone see what needs to be changed?

Will Sargent

unread,
Jun 13, 2016, 2:23:29 PM6/13/16
to play-fr...@googlegroups.com
You need to provide some extra type information -- here, you're calling Done() with redirToLogin and Input.Empty, but the compiler is not finding the ByteString type from redirToLogin.

Try explicitly defining the type:

val bytes: akka.util.ByteString = redirToLogin(request)
Done(bytes, Input.Empty)

and that should lead you to an error message that gives you more info.

Will.


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/02f5ef32-df22-4f93-b0b5-ed96fbf34c97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Will Sargent

unread,
Jun 13, 2016, 2:25:00 PM6/13/16
to play-fr...@googlegroups.com
Okay, I was jumping the gun.

You're passing back an Iteratee.  You need to pass back an Accumulator.  Check out:


and that should help you.

Jon Kleiser

unread,
Jun 14, 2016, 4:42:35 AM6/14/16
to play-framework
Hi Will,

Thanks for mentioning Accumulator. I changed the problematic line, and it now compiles. Looks good.

  def Authenticated[A]()(action: User => EssentialAction): EssentialAction = {

    EssentialAction { request =>
      getLoggedInUser(request).map { userInfo =>
        action(userInfo)(request)
      }.getOrElse {
        play.api.libs.streams.Accumulator.done(redirToLogin(request))
Reply all
Reply to author
Forward
0 new messages