diff --git a/src/cg/01-stdlib.cg b/src/cg/01-stdlib.cg index 9e68ca6..562e5b5 100644 --- a/src/cg/01-stdlib.cg +++ b/src/cg/01-stdlib.cg @@ -1,7 +1,7 @@ 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"; +myPoint = point 3 Blah; # builtins # TODO: once we get typeclasses, make these the actual types diff --git a/src/typechecker.ts b/src/typechecker.ts index da00fe0..e813d4a 100644 --- a/src/typechecker.ts +++ b/src/typechecker.ts @@ -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); + } } } }