Skip to content

Awaiting on Future via suggested extensions is not very practical with type hierarchies #1356

@bdmendes

Description

@bdmendes

The following example should be illustrative:

class A
class B extends A

def foo: Future[A] = ???

Await.result(foo, 1.second) === new B // ok

Await.result(foo, 1.second) must beEqualTo(new B) // ok

foo must beEqualTo(new B).await // does not compile
                                // Found: org.specs2.matcher.EqualityMatcher[B]
                                // Required: org.specs2.matcher.Matcher[A]

This makes testing async APIs tedious, as one needs to:

foo must beEqualTo[A](new B).await

I am not sure what's the best way to fix it. I tried:

extension [F[_] <: Matcher[_], T](m: F[T])(using ee: ExecutionEnv) {
  def awaitMine: F[Future[T]] = ???
}

But the problem is not that the extension is not the generic type, but rather, I think, that the compiler does not know that it needs to widen B to A before attempting the extension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions