From 823ea0e8f1d6797ead62e5012af8f6961b4e1a85 Mon Sep 17 00:00:00 2001 From: Michael Schimmel Date: Mon, 29 Sep 2025 11:41:01 +0200 Subject: [PATCH] Fixed parser error in fn def --- Src/AST/Myc.Ast.Script.pas | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Src/AST/Myc.Ast.Script.pas b/Src/AST/Myc.Ast.Script.pas index fdfccb0..076b7c3 100644 --- a/Src/AST/Myc.Ast.Script.pas +++ b/Src/AST/Myc.Ast.Script.pas @@ -348,7 +348,14 @@ begin Result := TAst.Assign(IIdentifierNode(tailNodes[0]), tailNodes[1]); end else if SameText(head.Token.Text, 'fn') then - Result := TAst.LambdaExpr(elements[High(tailNodes)].Params, tailNodes[1]) + begin + // Corrected handling for lambda expressions + if Length(tailNodes) <> 2 then + raise Exception.Create('Syntax Error: ''fn'' requires a parameter list and a body.'); + if elements[1].Node <> nil then + raise Exception.Create('Syntax Error: Expected a parameter list [...] after ''fn''.'); + Result := TAst.LambdaExpr(elements[1].Params, tailNodes[1]); + end else if SameText(head.Token.Text, 'do') then Result := TAst.Block(tailNodes) else if SameText(head.Token.Text, 'recur') then