Type checking unannotated expressions
This commit is contained in:
parent
de83eb6fcd
commit
a4daf88085
2 changed files with 9 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
point : Int \ Int \ { x : Int, y : Int } = x y \ { x = x, y = y };
|
point : Int \ Int \ { x : Int, y : Int } = x y \ { x = x, y = y };
|
||||||
getX : { x : Int, y : Int } \ Int = p \ p.x;
|
getX : { x : Int, y : Int } \ Int = p \ p.x;
|
||||||
setX : Int \ { x : Int, y : Int } \ { x : Int, y : Int } = newX p \ p.{ x = newX };
|
setX : Int \ { x : Int, y : Int } \ { x : Int, y : Int } = newX p \ p.{ x = newX };
|
||||||
myPoint = point 3 "a";
|
myPoint = point 3 Blah;
|
||||||
|
|
||||||
# builtins
|
# builtins
|
||||||
# TODO: once we get typeclasses, make these the actual types
|
# TODO: once we get typeclasses, make these the actual types
|
||||||
|
|
|
||||||
|
|
@ -340,10 +340,15 @@ export function typecheck(defs: Definition[], typeDefs: TypeDefinition[] = []) {
|
||||||
|
|
||||||
// Check each annotated def
|
// Check each annotated def
|
||||||
for (const def of defs) {
|
for (const def of defs) {
|
||||||
if (def.annotation && def.body) {
|
if (def.body) {
|
||||||
const subst: Subst = new Map();
|
const subst: Subst = new Map();
|
||||||
|
if (def.annotation) {
|
||||||
const err = check(def.body, def.annotation.type, env, subst);
|
const err = check(def.body, def.annotation.type, env, subst);
|
||||||
if (err) warn(err, def.body);
|
if (err) warn(err, def.body);
|
||||||
|
} else {
|
||||||
|
const t = infer(def.body, env, subst);
|
||||||
|
if (t) env.set(def.name, t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue