when assigning parameter to function, the returned typevar substitutions must take into account any typevar recomputations

This commit is contained in:
Joeri Exelmans 2025-05-18 09:58:11 +02:00
parent 8266e59b94
commit 248d8ddef1
2 changed files with 25 additions and 9 deletions

View file

@ -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);