fixed some bugs

This commit is contained in:
Robin Bärtschi 2025-02-28 13:06:10 +01:00
parent 508b3fdc7a
commit 6425cd3b55
4 changed files with 14 additions and 8 deletions

View File

@ -175,7 +175,10 @@ 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
// 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() {}

View File

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

View File

@ -8,6 +8,6 @@ fn main() = {
else {
hi = 1
};
test2
};
fn test2() = {};

View File

@ -118,7 +118,9 @@ func VarResolveExpr(s *Scope, e ast.Expression) error {
for _, e := range e.Expressions {
errs = append(errs, VarResolveExpr(&newS, e))
}
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 {