feat: semantic error messages make use of msg strings passed from typeChecker
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user