From 603ecbc22bc37378ed3ea1a8abf74fb2dc2329af Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 29 Dec 2022 09:59:47 +0800 Subject: prevent using declared global variables as temporary inline variables. --- src/yuescript/yue_compiler.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 42310b2..db59c08 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -71,7 +71,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.15.19"sv; +const std::string_view version = "0.15.20"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -417,6 +417,19 @@ private: return isDefined; } + bool isSolidDefined(const std::string& name) const { + bool defined = false; + for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { + auto vars = it->vars.get(); + auto vit = vars->find(name); + if (vit != vars->end()) { + defined = true; + break; + } + } + return defined; + } + bool isLocal(const std::string& name) const { bool local = false; for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { @@ -526,7 +539,7 @@ private: do { newName = nameStr + std::to_string(index); index++; - } while (isLocal(newName)); + } while (isSolidDefined(newName)); return newName; } -- cgit v1.2.3-55-g6feb