From ce3fbe6ceded65c6a5597c16ff4f3b5d4b82782a Mon Sep 17 00:00:00 2001 From: Nocturn9x Date: Fri, 29 Oct 2021 12:38:59 +0200 Subject: [PATCH] Fixed bug that always parsed function bodies as empty blocks --- src/backend/parser.nim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/backend/parser.nim b/src/backend/parser.nim index 66283a8..9eccf6c 100644 --- a/src/backend/parser.nim +++ b/src/backend/parser.nim @@ -755,7 +755,6 @@ proc varDecl(self: Parser, isStatic: bool = true, isPrivate: bool = true): ASTNo discard # Unreachable - proc funDecl(self: Parser, isAsync: bool = false, isStatic: bool = true, isPrivate: bool = true, isLambda: bool = false): ASTNode = ## Parses function and lambda declarations. Note that lambdas count as expressions! var enclosingFunction = self.currentFunction @@ -763,11 +762,10 @@ proc funDecl(self: Parser, isAsync: bool = false, isStatic: bool = true, isPriva self.context = Function var arguments: seq[ASTNode] = @[] var defaults: seq[ASTNode] = @[] - var body: ASTNode = newBlockStmt(@[]) if not isLambda: - self.currentFunction = newFunDecl(nil, arguments, defaults, body, isAsync=isAsync, isGenerator=false, isStatic=isStatic, isPrivate=isPrivate) + self.currentFunction = newFunDecl(nil, arguments, defaults, newBlockStmt(@[]), isAsync=isAsync, isGenerator=false, isStatic=isStatic, isPrivate=isPrivate) else: - self.currentFunction = newLambdaExpr(arguments, defaults, body, isGenerator=false) + self.currentFunction = newLambdaExpr(arguments, defaults, newBlockStmt(@[]), isGenerator=false) if not isLambda: self.expect(Identifier, "expecting function name after 'fun'") FunDecl(self.currentFunction).name = newIdentExpr(self.peek(-1)) @@ -793,7 +791,10 @@ proc funDecl(self: Parser, isAsync: bool = false, isStatic: bool = true, isPriva break self.expect(RightParen) self.expect(LeftBrace) - body = self.blockStmt() + if not isLambda: + FunDecl(self.currentFunction).body = self.blockStmt() + else: + LambdaExpr(self.currentFunction).body = self.blockStmt() self.context = enclosingContext result = self.currentFunction self.currentFunction = enclosingFunction