From 6425cd3b552b21d6761215cefbab3e3959d54458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20B=C3=A4rtschi?= Date: Fri, 28 Feb 2025 13:06:10 +0100 Subject: [PATCH] fixed some bugs --- ast/ast.go | 9 ++++++--- build/task.go | 3 ++- test.tt | 4 ++-- typechecker/variable_resolution.go | 6 ++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ast/ast.go b/ast/ast.go index 8e86db8..023aa07 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -173,9 +173,12 @@ func (be *BinaryExpression) String() string { } type BlockExpression struct { - Token token.Token // The '{' - Expressions []Expression - ReturnExpression Expression // A expression that does not end with a semicolon, there can only be one of those and it hast to be at the end + Token token.Token // The '{' + Expressions []Expression + // NOTE: Nullable + // + // A expression that does not end with a semicolon, there can only be one of those and it has to be at the end + ReturnExpression Expression } func (be *BlockExpression) expressionNode() {} diff --git a/build/task.go b/build/task.go index d910004..aa6805c 100644 --- a/build/task.go +++ b/build/task.go @@ -6,6 +6,7 @@ import ( "io" "os" "os/exec" + "runtime/debug" "slices" "strings" @@ -149,7 +150,7 @@ func build(outputWriter io.Writer, input string, output string, toPrint ToPrintF defer func() { if panicErr := recover(); panicErr != nil { - err = fmt.Errorf("panic in build: %#v", panicErr) + err = fmt.Errorf("panic in build: %#v\n%s", panicErr, debug.Stack()) } }() diff --git a/test.tt b/test.tt index 8d848d6..bbeb911 100644 --- a/test.tt +++ b/test.tt @@ -8,6 +8,6 @@ fn main() = { else { hi = 1 }; - - test2 }; + +fn test2() = {}; diff --git a/typechecker/variable_resolution.go b/typechecker/variable_resolution.go index 7af48e3..a5f6481 100644 --- a/typechecker/variable_resolution.go +++ b/typechecker/variable_resolution.go @@ -118,7 +118,9 @@ func VarResolveExpr(s *Scope, e ast.Expression) error { for _, e := range e.Expressions { errs = append(errs, VarResolveExpr(&newS, e)) } - errs = append(errs, VarResolveExpr(&newS, e.ReturnExpression)) + if e.ReturnExpression != nil { + errs = append(errs, VarResolveExpr(&newS, e.ReturnExpression)) + } return errors.Join(errs...) case *ast.IfExpression: @@ -145,7 +147,7 @@ func VarResolveExpr(s *Scope, e ast.Expression) error { return errorf(e.Token, "variable %q redefined", e.Identifier) } - s.SetUniq(e.Identifier) + e.Identifier = s.SetUniq(e.Identifier) case *ast.VariableReference: v, ok := s.Get(e.Identifier) if !ok {