fix: check function calls have correct number of args
This commit is contained in:
parent
e57c89beec
commit
277d2f66af
@ -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)
|
||||
|
@ -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}"))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user