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
|
|
@ -68,10 +68,12 @@ export const mergeTwoWay = (m1, m2) => {
|
|||
checkConflict(m1, m2);
|
||||
// checkConflict(m2, m1); // <- don't think this is necessary...
|
||||
// actually merge
|
||||
let stable = false;
|
||||
while (!stable) {
|
||||
let remaining = 2;
|
||||
while (remaining > 0) {
|
||||
// notice we swap m2 and m1, so the rewriting can happen both ways:
|
||||
let stable;
|
||||
[stable, m2, m1] = mergeOneWay(m1, m2);
|
||||
remaining -= stable;
|
||||
}
|
||||
const result = new Map([...m1, ...m2]);
|
||||
// console.log("mergeTwoWay result =", result);
|
||||
|
|
@ -187,8 +189,7 @@ export const substitute = (type, substitutions, stack=[]) => {
|
|||
};
|
||||
|
||||
export const assignFn = (funType, paramType) => {
|
||||
const [outType] = assignFnSubstitutions(funType, paramType);
|
||||
return outType;
|
||||
return assignFnSubstitutions(funType, paramType)[2];
|
||||
};
|
||||
|
||||
// same as above, but also returns the substitutions that took place
|
||||
|
|
@ -197,12 +198,13 @@ export const assignFnSubstitutions = (funType, paramType) => {
|
|||
throw new NotAFunctionError(`${prettyT(funType)} is not a function type!`);
|
||||
}
|
||||
const [[refunType, funS], [reparamType, paramS]] = recomputeTypeVarsSubstitutions([funType, paramType]);
|
||||
const recomputationSubstitutions = mergeTwoWay(funS, paramS);
|
||||
const [inType, outType] = refunType.params.map(p => p(refunType));
|
||||
const {substitutions} = __unify(inType, reparamType);
|
||||
// console.log(substitutions, prettyT(outType));
|
||||
const {type: newInType, substitutions} = __unify(inType, reparamType);
|
||||
const inTypeSubst = mergeTwoWay(substitutions, recomputationSubstitutions);
|
||||
const substitutedFnType = substitute(outType, substitutions);
|
||||
const computedOutType = recomputeTypeVars([substitutedFnType])[0];
|
||||
return [computedOutType, substitutions];
|
||||
const [computedOutType, outSubst] = recomputeTypeVarsSubstitutions([substitutedFnType])[0];
|
||||
return [newInType, inTypeSubst, computedOutType, outSubst];
|
||||
};
|
||||
|
||||
// Ensures that no type variables overlap
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue