Type checking unannotated expressions

This commit is contained in:
Dustin Swan 2026-03-26 20:04:46 -06:00
parent de83eb6fcd
commit a4daf88085
No known key found for this signature in database
GPG key ID: 30D46587E2100467
2 changed files with 9 additions and 4 deletions

View file

@ -340,10 +340,15 @@ export function typecheck(defs: Definition[], typeDefs: TypeDefinition[] = []) {
// Check each annotated def
for (const def of defs) {
if (def.annotation && def.body) {
if (def.body) {
const subst: Subst = new Map();
const err = check(def.body, def.annotation.type, env, subst);
if (err) warn(err, def.body);
if (def.annotation) {
const err = check(def.body, def.annotation.type, env, subst);
if (err) warn(err, def.body);
} else {
const t = infer(def.body, env, subst);
if (t) env.set(def.name, t);
}
}
}
}