Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Nov 20, 2024
1 parent 8c9f285 commit 79365bf
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/type/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,36 @@ describe("unify traits", () => {
expect(resolvedTypeTraitsOfVar(u, ta)).toEqual([]);
expect(resolvedTypeTraitsOfVar(u, tb)).toEqual(["Eq"]);
});

test("failing unification of traits in nested deps", () => {
const u = new Unifier();
const result_ = result(_0, _1); // the passed type params are not relevant for the test

// Note that we are only imposing the constraint on the second parameter of Result
u.registerTraitImpl(result_.package, result_.module, result_.name, "Eq", [
false,
true,
]);

const t0 = u.freshVar(["Eq"]);
const ta = u.freshVar();
const tb = u.freshVar();
u.unify(t0, result(ta, tb));

// Note that Num does not implement Eq in this test

expect(() => {
u.unify(ta, num);
}).not.toThrow(MissingTraitError);

expect(() => {
u.unify(tb, num);
}).toThrow(MissingTraitError);

expect(() => {
u.unify(t0, result(num, num));
}).toThrow(MissingTraitError);
});
});

describe("instantiation", () => {
Expand Down

0 comments on commit 79365bf

Please sign in to comment.