feat: semantic error messages make use of msg strings passed from typeChecker

This commit is contained in:
Guy C
2025-02-07 12:46:47 +00:00
committed by Barf-Vader
parent c798fdf416
commit b6d8eb31e3
2 changed files with 15 additions and 29 deletions

View File

@@ -6,7 +6,6 @@ import wacc.types._
enum Error {
case DuplicateDeclaration(ident: ast.Ident)
case UndefinedIdentifier(ident: ast.Ident, identType: renamer.IdentType)
case FunctionParamsMismatch(pos: Position, expected: Int, got: Int)
case SemanticError(pos: Position, msg: String)
case TypeMismatch(pos: Position, expected: SemType, got: SemType, msg: String)
@@ -18,25 +17,23 @@ def printError(error: Error)(using errorContent: String): Unit = {
error match {
case Error.DuplicateDeclaration(ident) =>
printPosition(ident.getPosition)
println(
s"Duplicate declaration of identifier ${ident.v}"
)
println(s"Duplicate declaration of identifier ${ident.v}")
highlight(ident.getPosition, ident.v.length)
case Error.UndefinedIdentifier(ident, identType) =>
printPosition(ident.getPosition)
println(
s"Undefined ${identType.toString.toLowerCase()} ${ident.v}"
)
println(s"Undefined ${identType.toString.toLowerCase()} ${ident.v}")
highlight(ident.getPosition, ident.v.length)
case Error.FunctionParamsMismatch(pos, expected, got) =>
printPosition(pos)
println(s"Function expects $expected parameters, got $got")
highlight(pos, 1)
case Error.TypeMismatch(pos, expected, got, msg) =>
println(s"Type mismatch: expected $expected, got $got")
printPosition(pos)
println(msg)
highlight(pos, 1)
case Error.SemanticError(pos, msg) =>
printPosition(pos)
println(s"$msg at line: ${pos.line} column: ${pos.column}")
println(msg)
highlight(pos, 1)
case wacc.Error.InternalError(pos, msg) =>
printPosition(pos)