when assigning parameter to function, the returned typevar substitutions must take into account any typevar recomputations
This commit is contained in:
parent
8266e59b94
commit
248d8ddef1
2 changed files with 25 additions and 9 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import assert from "node:assert";
|
||||
import { assignFn, makeGeneric, unify, UnifyError } from "../lib/generics/generics.js";
|
||||
import { assignFn, assignFnSubstitutions, makeGeneric, unify, UnifyError } from "../lib/generics/generics.js";
|
||||
import { getDefaultTypeParser } from "../lib/parser/type_parser.js";
|
||||
import { prettyT } from "../lib/util/pretty.js";
|
||||
import { TYPE_VARS, UNBOUND_SYMBOLS } from "../lib/primitives/typevars.js";
|
||||
|
||||
const mkType = getDefaultTypeParser();
|
||||
|
||||
|
|
@ -65,3 +66,16 @@ assert.throws(
|
|||
// expected error
|
||||
UnifyError,
|
||||
);
|
||||
|
||||
const [inType, inSubst, outType, outSubst] = assignFnSubstitutions(
|
||||
mkType("Int -> Int"),
|
||||
mkType("b"),
|
||||
);
|
||||
|
||||
assert.equal(prettyT(inType), "Int");
|
||||
assert.equal(prettyT(outType), "Int");
|
||||
assert.equal(inSubst.size, 1);
|
||||
assert.equal(prettyT(
|
||||
inSubst.get(UNBOUND_SYMBOLS[1]) // b
|
||||
), "Int")
|
||||
assert.equal(outSubst.size, 0);
|
||||
Loading…
Add table
Add a link
Reference in a new issue