Skip to content

js runtime: CAPTURE drops the return value #1016

Open
@marzipankaiser

Description

@marzipankaiser

When using CAPTURE in the javascript backend, this replaces the return value by $effekt.unit. Some of the existing FFI relies on this behavior (we then don't have to explicitly return unit):

function CAPTURE(body) {
return (ks, k) => {
const res = body(x => TRAMPOLINE(() => k(x, ks)))
if (res instanceof Function) return res
else throw { computationIsDone: true, result: $effekt.unit }
}
}

Example program

The following program triggers above behavior via promise.resolve.

import io

extern io def rT[T](run: => T at {io, async, global}): T =
  js "$effekt.runToplevel((ks, k) => ${run}(ks, k))"

def main() = {
  val pr = promise::make[Int]()
  println(rT[Int](box {
    pr.resolve(2);
    12
  }))
}

Playground


Thanks @b-studios for helping to find the underlying cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions