fix: extract retType from KnownType.Func when type-checking function bodies
This commit is contained in:
parent
f6e734937f
commit
e57c89beec
@ -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")))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user