From 849ea7c923f9e385f17af73472bbb611f917993e Mon Sep 17 00:00:00 2001 From: Sainan Date: Wed, 19 Jul 2023 22:44:51 +0200 Subject: [PATCH] Alternative observation --- src/llex.h | 1 + src/lparser.cpp | 12 ++++++++++-- tests/basic.pluto | 25 ------------------------- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/llex.h b/src/llex.h index cbb0515ca3..ce3aed7ea1 100644 --- a/src/llex.h +++ b/src/llex.h @@ -319,6 +319,7 @@ struct LexState { std::vector enums{}; std::vector export_symbols{}; std::vector parse_time_allocations{}; + bool should_have_extends = false; LexState() : lines{ std::string{} }, warnconfs{ WarningConfig(0) } diff --git a/src/lparser.cpp b/src/lparser.cpp index 124c6949d4..df633c0d8b 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -1018,6 +1018,13 @@ static void leaveblock (FuncState *fs) { } luaK_patchtohere(fs, bl->breaklist); ls->laststat.token = TK_EOS; /* Prevent unreachable code warnings on blocks that don't explicitly check for TK_END. */ + + if (ls->should_have_extends && bl->nactvar != 0) { + expdesc f; + singlevaraux(fs, luaS_newliteral(ls->L, "Pluto_operator_extends"), &f, 1); + if (f.k == VVOID) + luaX_syntaxerror(ls, "what the fuck?"); + } } @@ -1521,8 +1528,7 @@ static void applyextends (LexState *ls, expdesc *v, TString *parent, int line) { expdesc f; singlevaraux(fs, luaS_newliteral(ls->L, "Pluto_operator_extends"), &f, 1); - if (f.k == VVOID) - luaX_syntaxerror(ls, "what the fuck?"); + lua_assert(f.k != VVOID); luaK_exp2nextreg(fs, &f); expdesc args = *v; @@ -4625,7 +4631,9 @@ static void mainfunc (LexState *ls, FuncState *fs) { luaC_objbarrier(ls->L, fs->f, env->name); builtinoperators(ls); luaX_next(ls); /* read first token */ + ls->should_have_extends = true; const bool ret = statlist(ls); /* parse main body */ + ls->should_have_extends = false; check(ls, TK_EOS); if (!ls->export_symbols.empty()) { if (ret) { diff --git a/tests/basic.pluto b/tests/basic.pluto index 1e92be6f28..3e0e7f8c17 100644 --- a/tests/basic.pluto +++ b/tests/basic.pluto @@ -1260,31 +1260,6 @@ do class Human end end -print "Testing compile-time conditionals." -do - local debug_bytecode = string.dump(load([[ - local DEBUG = true - $if DEBUG then - print("Script running in debug mode") - $else - print("Script running in release mode") - $end - ]], "")) - local release_bytecode = string.dump(load([[ - local DEBUG = false - $if DEBUG then - print("Script running in debug mode") - $else - print("Script running in release mode") - $end - ]], "")) - - assert(debug_bytecode:find("Script running in debug mode") ~= nil) - assert(debug_bytecode:find("Script running in release mode") == nil) - assert(release_bytecode:find("Script running in debug mode") == nil) - assert(release_bytecode:find("Script running in release mode") ~= nil) -end - print "Testing compatibility." do local a = "Hi"