fix: extract retType from KnownType.Func when type-checking function bodies

This commit is contained in:
Gleb Koval 2025-02-06 23:59:13 +00:00
parent f6e734937f
commit e57c89beec
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

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")))
} }