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