More type checking
This commit is contained in:
parent
668ee3e4d8
commit
de83eb6fcd
2 changed files with 22 additions and 0 deletions
|
|
@ -127,6 +127,23 @@ function infer(expr: AST, env: TypeEnv, subst: Subst): TypeAST | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
case 'record-update': {
|
||||
const recType = infer(expr.record, env, subst);
|
||||
if (!recType) return null;
|
||||
const resolved = applySubst(recType, subst);
|
||||
if (resolved.kind !== 'type-record') return null;
|
||||
|
||||
for (const [key, value] of Object.entries(expr.updates)) {
|
||||
const field = resolved.fields.find(f => f.name === key);
|
||||
if (field) {
|
||||
const err = check(value, field.type, env, subst);
|
||||
if (err) warn(err, value);
|
||||
}
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
case 'apply': {
|
||||
const funcType = infer(expr.func, env, subst);
|
||||
if (!funcType) return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue