diff --git a/src/main/wacc/Error.scala b/src/main/wacc/Error.scala index fec2662..0f3c01d 100644 --- a/src/main/wacc/Error.scala +++ b/src/main/wacc/Error.scala @@ -10,7 +10,7 @@ enum Error { case UndeclaredVariable(ident: ast.Ident) case UndefinedFunction(ident: ast.Ident) - case FunctionParamsMismatch(pos: Position, expected: Int, got: Int) + case FunctionParamsMismatch(ident: ast.Ident, expected: Int, got: Int, funcType: FuncType) case SemanticError(pos: Position, msg: String) case TypeMismatch(pos: Position, expected: SemType, got: SemType, msg: String) case InternalError(pos: Position, msg: String) @@ -38,10 +38,13 @@ def printError(error: Error)(using errorContent: String): Unit = { printPosition(ident.pos) println(s"Undefined function ${ident.v}") highlight(ident.pos, ident.v.length) - case Error.FunctionParamsMismatch(pos, expected, got) => - printPosition(pos) + case Error.FunctionParamsMismatch(id, expected, got, funcType) => + printPosition(id.pos) println(s"Function expects $expected parameters, got $got") - highlight(pos, 1) + println( + s"(function ${id.v} has type (${funcType.params.mkString(", ")}) -> ${funcType.returnType})" + ) + highlight(id.pos, 1) case Error.TypeMismatch(pos, expected, got, msg) => printPosition(pos) println(s"Type mismatch: $msg\nExpected: $expected\nGot: $got") diff --git a/src/main/wacc/typeChecker.scala b/src/main/wacc/typeChecker.scala index 80eda2e..c766905 100644 --- a/src/main/wacc/typeChecker.scala +++ b/src/main/wacc/typeChecker.scala @@ -189,9 +189,9 @@ object typeChecker { ) .satisfies(constraint, l.pos) case Call(id, args) => - val FuncType(retTy, paramTys) = ctx.funcType(id) + val funcTy @ FuncType(retTy, paramTys) = ctx.funcType(id) if (args.length != paramTys.length) { - ctx.error(Error.FunctionParamsMismatch(id.pos, paramTys.length, args.length)) + ctx.error(Error.FunctionParamsMismatch(id, paramTys.length, args.length, funcTy)) } args.zip(paramTys).foreach { case (arg, paramTy) => checkValue(arg, Constraint.Is(paramTy, s"argument type mismatch in function ${id.v}"))