diff --git a/src/component/expr/CallBlock.tsx b/src/component/expr/CallBlock.tsx index 9e199fe..e7d195c 100644 --- a/src/component/expr/CallBlock.tsx +++ b/src/component/expr/CallBlock.tsx @@ -97,7 +97,7 @@ function InputParams({ ...rest }) { const globalContext = useContext(GlobalContext); const typeInfo = inferTypeCall(rest.state, env); const inputEnv = typeInfo.fn.newEnv; - const isOffending = rest.state.err; + const isOffending = typeInfo.err; return
{rest.state.fn.kind === "call" && globalContext?.syntacticSugar diff --git a/src/eval/infer_type.ts b/src/eval/infer_type.ts index 218e2f4..1065765 100644 --- a/src/eval/infer_type.ts +++ b/src/eval/infer_type.ts @@ -101,7 +101,6 @@ export function inferTypeInput(s: InputBlockState, env: Environment): TypeInfoIn } } -// @ts-ignore export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfoCall { const fnTypeInfo = inferType(s.fn, env); const inputEnv = fnTypeInfo.newEnv; @@ -112,7 +111,6 @@ export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfoCall const subs = unify( fnTypeInfo.type, fakeFnType); - // console.log("subs:", prettySS(subs)); let type, newEnv; if (subs.has(returnType!.symbol)) { type = subs.get(returnType!.symbol); @@ -159,6 +157,7 @@ export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfoCall input: inputTypeInfo, } } + throw e; } } @@ -195,13 +194,13 @@ export function inferTypeLambda(s: LambdaBlockState, env: Environment): TypeInfo const subsWithoutPType = new Map(innerTypeInfo.subs); subsWithoutPType.delete(paramTypeVar); const inferredPType = substitute(paramType, innerTypeInfo.subs, []); - const inferredPType2 = rewriteInferredType(inferredPType, env); + const [inferredPType2, newEnv] = rewriteInferredType(inferredPType, env); if (eqType(inferredPType2)(paramType)) { return { kind: "lambda", type: fnType(_ => paramType)(_ => innerTypeInfo.type), subs: subsWithoutPType, - newEnv: env, // no change + newEnv, paramType, inner: innerTypeInfo, innerEnv, @@ -245,8 +244,9 @@ function typeUnknown(env: Environment): [Type, Environment] { }; return [type, newEnv]; } -function rewriteInferredType(type: Type, env: Environment) { +function rewriteInferredType(type: Type, env: Environment): [Type, Environment] { const substitutions = new Map(); + const newTypeVars = new Set(env.typevars); let i = 0; for (const o of occurring(type)) { while (env.typevars.has(UNBOUND_SYMBOLS[i])) { @@ -254,9 +254,14 @@ function rewriteInferredType(type: Type, env: Environment) { } if (!env.typevars.has(o)) { substitutions.set(o, TYPE_VARS[i]); + newTypeVars.add(UNBOUND_SYMBOLS[i]); } } - return substitute(type, substitutions, []); + const rewrittenType = substitute(type, substitutions, []); + return [rewrittenType, { + names: env.names, + typevars: env.typevars.union(newTypeVars), + }]; } export function scoreTypeInfo(typeInfo: TypeInfo): number { const bias = typeInfo.err ? -1 : 0;