More type checking
This commit is contained in:
parent
668ee3e4d8
commit
de83eb6fcd
2 changed files with 22 additions and 0 deletions
|
|
@ -1,3 +1,8 @@
|
|||
point : Int \ Int \ { x : Int, y : Int } = x y \ { x = x, y = y };
|
||||
getX : { x : Int, y : Int } \ Int = p \ p.x;
|
||||
setX : Int \ { x : Int, y : Int } \ { x : Int, y : Int } = newX p \ p.{ x = newX };
|
||||
myPoint = point 3 "a";
|
||||
|
||||
# builtins
|
||||
# TODO: once we get typeclasses, make these the actual types
|
||||
cat : a \ a \ a;
|
||||
|
|
|
|||
|
|
@ -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