feat: full type checker without user-friendly error messages #11

Merged
gk1623 merged 7 commits from type-checker into master 2025-02-07 08:20:43 +00:00
8 changed files with 369 additions and 184 deletions
Showing only changes of commit e57c89beec - Show all commits

View File

@@ -74,10 +74,13 @@ object typeChecker {
ctx: TypeCheckerCtx ctx: TypeCheckerCtx
): Unit = { ): Unit = {
prog.funcs.foreach { case FuncDecl(_, name, _, stmts) => prog.funcs.foreach { case FuncDecl(_, name, _, stmts) =>
val retType = ctx.typeOf(name) ctx.typeOf(name) match {
case KnownType.Func(retType, _) =>
stmts.toList.foreach( stmts.toList.foreach(
checkStmt(_, Constraint.Is(retType, s"function ${name.v} must return $retType")) checkStmt(_, Constraint.Is(retType, s"function ${name.v} must return $retType"))
) )
case _ => ctx.error(Error.InternalError(name.pos, "function declaration with non-function"))
}
} }
prog.main.toList.foreach(checkStmt(_, Constraint.Never("main function must not return"))) prog.main.toList.foreach(checkStmt(_, Constraint.Never("main function must not return")))
} }