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
This commit is contained in:
Robin 2025-01-26 14:25:34 +01:00
parent ab7e332ac4
commit 6504ad7134
4 changed files with 4 additions and 4 deletions

View File

@ -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 {

View File

@ -1 +1 @@
fn main() = 3 + 3;
fn main() = 3 + 3 != false;

View File

@ -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())
}
}