Skip to content

Commit

Permalink
Mark promises covariant on JS
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Dec 30, 2019
1 parent 69dc502 commit c9d8008
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/js/promise.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@



type rejectable('a, 'e);
type rejectable(+'a, +'e);
type never;

type promise('a) = rejectable('a, never);
type t('a) = promise('a);
type promise(+'a) = rejectable('a, never);
type t(+'a) = promise('a);



Expand Down
8 changes: 4 additions & 4 deletions src/js/promise.rei
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@



type rejectable('a, 'e); /* Internal; use Promise.Js.t. */
type rejectable(+'a, +'e); /* Internal; use Promise.Js.t. */
type never;

type promise('a) = rejectable('a, never); /* Internal; use Promise.t. */
type t('a) = promise('a);
type promise(+'a) = rejectable('a, never); /* Internal; use Promise.t. */
type t(+'a) = promise('a);



Expand Down Expand Up @@ -155,7 +155,7 @@ let all6:

/* For writing bindings. */
module Js: {
type t('a, 'e) = rejectable('a, 'e);
type t(+'a, +'e) = rejectable('a, 'e);

/* Making. */
let pending:
Expand Down
59 changes: 58 additions & 1 deletion test/js/test_ffi.re
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,61 @@ let curryTests = Framework.suite("curry", [



let suites = [interopTests, soundnessTests, curryTests];
type type_ = [
| `A
| `B
]

type subtype = [
| `A
]

let covarianceTests = Framework.suite("covariance", [
test("promise", () => {
let p: Promise.t(subtype) = Promise.resolved(`A);
let p: Promise.t(type_) = (p :> Promise.t(type_));
ignore(p);
Promise.resolved(true);
}),

test("ok", () => {
let p: Promise.t(result(subtype, unit)) = Promise.resolved(Ok(`A));
let p: Promise.t(result(type_, unit)) =
(p :> Promise.t(result(type_, unit)));
ignore(p);
Promise.resolved(true);
}),

test("error", () => {
let p: Promise.t(result(unit, subtype)) = Promise.resolved(Error(`A));
let p: Promise.t(result(unit, type_)) =
(p :> Promise.t(result(unit, type_)));
ignore(p);
Promise.resolved(true);
}),

test("option", () => {
let p: Promise.t(option(subtype)) = Promise.resolved(Some(`A));
let p: Promise.t(option(type_)) = (p :> Promise.t(option(type_)));
ignore(p);
Promise.resolved(true);
}),

test("fulfillment", () => {
let p: Promise.Js.t(subtype, unit) = Promise.Js.resolved(`A);
let p: Promise.Js.t(type_, unit) = (p :> Promise.Js.t(type_, unit));
ignore(p);
Promise.resolved(true);
}),

test("rejection", () => {
let p: Promise.Js.t(unit, subtype) = Promise.Js.rejected(`A);
let p: Promise.Js.t(unit, type_) = (p :> Promise.Js.t(unit, type_));
p->Promise.Js.catch(_ => Promise.resolved())->ignore;
Promise.resolved(true);
}),
]);



let suites = [interopTests, soundnessTests, curryTests, covarianceTests];

0 comments on commit c9d8008

Please sign in to comment.