From 6681efe7706f7e4237c78e689ccc36e5de5d0ae3 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 7 Feb 2024 17:45:19 +0800 Subject: [PATCH] Update compiler.cpp --- src/compiler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index cc8f7937..4c97fc9f 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -33,7 +33,10 @@ namespace pkpy{ // previously, we only do this if the last opcode is not a return // however, this is buggy...since there may be a jump to the end (out of bound) even if the last opcode is a return ctx()->emit_(OP_RETURN_VALUE, 1, BC_KEEPLINE); - ctx()->co->end_line = prev().line; + // find the last valid token + int j = i-1; + while(tokens[j].type == TK("@eol") || tokens[j].type == TK("@dedent") || tokens[j].type == TK("@eof")) j--; + ctx()->co->end_line = tokens[j].line; // some check here std::vector& codes = ctx()->co->codes;