feat: type checker without satisfies implemented #12

Closed
gc1523 wants to merge 8 commits from master into semantic-error-messages
Showing only changes of commit e57c89beec - Show all commits

View File

@@ -74,10 +74,13 @@ object typeChecker {
ctx: TypeCheckerCtx
): Unit = {
prog.funcs.foreach { case FuncDecl(_, name, _, stmts) =>
val retType = ctx.typeOf(name)
ctx.typeOf(name) match {
case KnownType.Func(retType, _) =>
stmts.toList.foreach(
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")))
}