one last fix
This commit is contained in:
parent
ca9af544ba
commit
3ff7e76694
3 changed files with 21 additions and 15 deletions
|
|
@ -127,8 +127,10 @@ function InputParams({ depth, errorDepth, ...rest }) {
|
|||
errorDepth={errorDepth}
|
||||
/>}
|
||||
{/* Our own input param */}
|
||||
<EnvContext value={inferTypeCall(rest.state, env).inputEnv}>
|
||||
<ExprBlock
|
||||
{...nestedInputProperties(rest as CallBlockProps, env)}
|
||||
/>
|
||||
</EnvContext>
|
||||
</div>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@ function DeclColumns({state, setState, score}) {
|
|||
|
||||
const {paramType, innerEnv} = inferTypeLet(state, env);
|
||||
|
||||
// const innerEnv = env; // todo: change this
|
||||
|
||||
return <>
|
||||
<span className="keyword column">let </span>
|
||||
<span className="column rightAlign">
|
||||
|
|
@ -95,7 +93,7 @@ function InnerMost({state, setState, score}) {
|
|||
const setInner = callback => setState(state => ({...state, inner: callback(state.inner)}));
|
||||
// const [valueResolved] = evalExprBlock(state.value, env);
|
||||
// const innerEnv = makeInnerEnv(env, state.name, valueResolved);
|
||||
const innerEnv = env; // todo: change this
|
||||
const {paramType, innerEnv} = inferTypeLet(state, env);
|
||||
const onCancel = () => setState(state => state.value);
|
||||
if (state.inner.kind === "let" && globalContext?.syntacticSugar) {
|
||||
return <EnvContext value={innerEnv}>
|
||||
|
|
|
|||
|
|
@ -25,10 +25,13 @@ export interface TypeInfo {
|
|||
err?: IncompatibleTypesError;
|
||||
}
|
||||
|
||||
export interface LambdaTypeInfo extends TypeInfo {
|
||||
export interface TypeInfoLambda extends TypeInfo {
|
||||
paramType: Type;
|
||||
innerEnv: Environment;
|
||||
}
|
||||
export interface TypeInfoCall extends TypeInfo {
|
||||
inputEnv: Environment;
|
||||
}
|
||||
|
||||
export function inferType(s: ExprBlockState, env: Environment): TypeInfo {
|
||||
if (s.kind === "input") {
|
||||
|
|
@ -60,11 +63,9 @@ export function inferTypeInput(s: InputBlockState, env: Environment): TypeInfo {
|
|||
else if (s.value.kind === "name") {
|
||||
const found = trie.get(env.names)(s.text);
|
||||
if (found) {
|
||||
let type = found.t;
|
||||
let newEnv = env;
|
||||
if (found.kind !== "unknown") {
|
||||
[type, newEnv] = rewriteType(found.t, env);
|
||||
}
|
||||
const [type, newEnv] = (found.kind === "unknown")
|
||||
? [found.t, env]
|
||||
: rewriteType(found.t, env);
|
||||
return {
|
||||
type,
|
||||
subs: new Map(),
|
||||
|
|
@ -82,9 +83,10 @@ export function inferTypeInput(s: InputBlockState, env: Environment): TypeInfo {
|
|||
}
|
||||
|
||||
// @ts-ignore
|
||||
export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfo {
|
||||
export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfoCall {
|
||||
const fnTypeInfo = inferType(s.fn, env);
|
||||
const inputTypeInfo = inferType(s.input, fnTypeInfo.newEnv);
|
||||
const inputEnv = fnTypeInfo.newEnv;
|
||||
const inputTypeInfo = inferType(s.input, inputEnv);
|
||||
const [returnType, envWithReturn] = typeUnknown(inputTypeInfo.newEnv);
|
||||
const fakeFnType = fnType(_ => inputTypeInfo.type)(_ => returnType);
|
||||
try {
|
||||
|
|
@ -111,6 +113,7 @@ export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfo {
|
|||
type,
|
||||
subs: mergedSubs,
|
||||
newEnv,
|
||||
inputEnv,
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
|
|
@ -121,17 +124,20 @@ export function inferTypeCall(s: CallBlockState, env: Environment): TypeInfo {
|
|||
subs: new Map(),
|
||||
newEnv,
|
||||
err: e,
|
||||
inputEnv,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function inferTypeLet(s: LetInBlockState, env: Environment): LambdaTypeInfo {
|
||||
export function inferTypeLet(s: LetInBlockState, env: Environment): TypeInfoLambda {
|
||||
const valTypeInfo = inferType(s.value, env);
|
||||
const innerEnv = {
|
||||
names: trie.insert(env.names)(s.name)({kind: "value", t: valTypeInfo.type}),
|
||||
typevars: env.typevars,
|
||||
};
|
||||
console.log(s.name);
|
||||
console.log("innerEnv.names:", innerEnv.names);
|
||||
return {
|
||||
...inferType(s.inner, innerEnv),
|
||||
paramType: valTypeInfo.type,
|
||||
|
|
@ -140,7 +146,7 @@ export function inferTypeLet(s: LetInBlockState, env: Environment): LambdaTypeIn
|
|||
}
|
||||
|
||||
|
||||
export function inferTypeLambda(s: LambdaBlockState, env: Environment): LambdaTypeInfo {
|
||||
export function inferTypeLambda(s: LambdaBlockState, env: Environment): TypeInfoLambda {
|
||||
let [paramType] = typeUnknown(env);
|
||||
const paramTypeVar = paramType.symbol;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue