Skip to content

Tests for capture checking #67

@odersky

Description

@odersky

When we get capture checked Gears it would be good that the following works as expected:

val good1: List[Future[Result[T]]] -> Future[Result[List[T]]] = frs =>
  Future:
    Result:
      frs.map(_.await.ok)

val good2: Result[Future[T]] -> Future[Result[T]] = rf =>
  Future:
    Result:
      rf.ok.await  // OK, Future argument has type Result[T]

On the other hand, the following case should fail:

val fail3: Future[Result[T]] -> Result[Future[T]] = fr =>
  Result: 
    Future:
      fr.await.ok // error, escaping label from Result

This fails because it is expanded to

val fail3: Future[Result[T]] -> Result[Future[T]] = fr =>
  Result: lbl ?=> 
    Future:
      fr.await.ok(using lbl) // error, escaping label from Result

and the Future block has type Future[T]^{async, lbl}.
A transform having that type can be constructed but would be useless since we take a future of a value:

val useless4: Future[Result[T]] -> Result[Future[T]] = fr =>
  fr.await.map(Future(_))

The difference between good2 and fail3 is that Result is strict and Future is not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions