fix: check function calls have correct number of args

This commit is contained in:
Gleb Koval 2025-02-07 00:09:10 +00:00
parent e57c89beec
commit 277d2f66af
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
2 changed files with 5 additions and 2 deletions

View File

@ -6,8 +6,8 @@ import wacc.types._
enum Error {
case DuplicateDeclaration(ident: ast.Ident)
case UndefinedIdentifier(ident: ast.Ident, identType: renamer.IdentType)
case FunctionParamsMismatch(expected: Int, got: Int) // TODO not fine
case FunctionParamsMismatch(pos: Position, expected: Int, got: Int)
case SemanticError(pos: Position, msg: String)
case TypeMismatch(pos: Position, expected: SemType, got: SemType, msg: String)
case InternalError(pos: Position, msg: String)

View File

@ -176,7 +176,10 @@ object typeChecker {
case Call(id, args) =>
val funcTy = ctx.typeOf(id)
funcTy match {
case KnownType.Func(retTy, paramTys) => // TODO do we check argument lengths match
case KnownType.Func(retTy, paramTys) =>
if (args.length != paramTys.length) {
ctx.error(Error.FunctionParamsMismatch(id.pos, paramTys.length, args.length))
}
args.zip(paramTys).foreach { case (arg, paramTy) =>
checkValue(arg, Constraint.Is(paramTy, s"argument type mismatch in function ${id.v}"))
}