From 08b68269ff6d6f868242dcefce75e1db26e4de61 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sun, 23 Mar 2025 17:25:28 +0800 Subject: Fixed issue #198. --- src/yuescript/yue_compiler.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 3d98fbc..e3c9d31 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -75,7 +75,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.27.1"sv; +const std::string_view version = "0.27.2"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -437,7 +437,6 @@ private: #endif std::unique_ptr> vars; std::unique_ptr> allows; - std::unique_ptr> globals; }; std::list _scopes; static const std::string Empty; @@ -516,10 +515,8 @@ private: int mode = int(std::isupper(name[0]) ? GlobalMode::Capital : GlobalMode::Any); const auto& current = _scopes.back(); if (int(current.mode) >= mode) { - if (!current.globals) { - isDefined = true; - current.vars->insert_or_assign(name, VarType::Global); - } + isDefined = true; + current.vars->insert_or_assign(name, VarType::Global); } decltype(_scopes.back().allows.get()) allows = nullptr; for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { @@ -892,10 +889,6 @@ private: void addGlobalVar(const std::string& name, ast_node* x) { if (isLocal(name)) throw CompileError("can not declare a local variable to be global"sv, x); auto& scope = _scopes.back(); - if (!scope.globals) { - scope.globals = std::make_unique>(); - } - scope.globals->insert(name); scope.vars->insert_or_assign(name, VarType::Global); } @@ -9401,7 +9394,6 @@ private: auto classDecl = static_cast(item); if (classDecl->name) { if (auto var = classDecl->name->item.as()) { - markVarsGlobal(GlobalMode::Any); addGlobalVar(variableToString(var), classDecl->name->item); } } @@ -9416,7 +9408,6 @@ private: } break; case id(): { - markVarsGlobal(GlobalMode::Any); auto values = global->item.to(); if (values->valueList) { auto expList = x->new_ptr(); -- cgit v1.2.3-55-g6feb