From 6504ad7134f855050e375eb73f84e437bc8d6c3e Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 26 Jan 2025 14:25:34 +0100 Subject: [PATCH] fix: typechecker error handling - rename Architecture.md -> architecture.md - change error handling in typechecker to print the token loc for binary expressions and also not prefix the error when printed in cmd --- Architecture.md => architecture.md | 0 cmd/cmd.go | 2 +- test.tt | 2 +- typechecker/check.go | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename Architecture.md => architecture.md (100%) diff --git a/Architecture.md b/architecture.md similarity index 100% rename from Architecture.md rename to architecture.md diff --git a/cmd/cmd.go b/cmd/cmd.go index ff1fe8d..3c1026a 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -128,7 +128,7 @@ func Compile(args Arguments) { tprogram, err := typechecker.New().CheckProgram(program) if err != nil { - fmt.Printf("Typechecker failed with: %v\n", err) + fmt.Printf("%v\n", err) os.Exit(1) } if (args.ToPrint & PrintTAst) != 0 { diff --git a/test.tt b/test.tt index b854b64..57ee435 100644 --- a/test.tt +++ b/test.tt @@ -1 +1 @@ -fn main() = 3 + 3; +fn main() = 3 + 3 != false; diff --git a/typechecker/check.go b/typechecker/check.go index 6dfa2c6..2fba81d 100644 --- a/typechecker/check.go +++ b/typechecker/check.go @@ -78,9 +78,9 @@ func (c *Checker) checkExpression(expr tast.Expression) error { var operandErr error if lhsErr == nil && rhsErr == nil { if !expr.Lhs.Type().IsSameType(expr.Rhs.Type()) { - operandErr = fmt.Errorf("the lhs of the expression does not have the same type then the rhs, lhs=%q, rhs=%q", expr.Lhs.Type().Name(), expr.Rhs.Type().Name()) + operandErr = c.error(expr.Token, "the lhs of the expression does not have the same type then the rhs, lhs=%q, rhs=%q", expr.Lhs.Type().Name(), expr.Rhs.Type().Name()) } else if !expr.Lhs.Type().SupportsBinaryOperator(expr.Operator) { - operandErr = fmt.Errorf("the operator %q is not supported by the type %q", expr.Operator, expr.Lhs.Type().Name()) + operandErr = c.error(expr.Token, "the operator %q is not supported by the type %q", expr.Operator, expr.Lhs.Type().Name()) } }