From 8ab0038c09a79fa8401bb10b7a31d03ef5380417 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 17 Jul 2020 16:22:11 +0800 Subject: fixed a missed case for multiline string as table key. reporting use of global variable 'tostring' . --- src/MoonP/moon_compiler.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 1283422..41d29df 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -49,7 +49,7 @@ inline std::string s(std::string_view sv) { } const std::string_view version() { - return "0.4.3"sv; + return "0.4.4"sv; } // name of table stored in lua registry @@ -3814,7 +3814,7 @@ private: } case id(): transformExp(static_cast(key), temp, ExpUsage::Closure); - temp.back() = s("["sv) + temp.back() + s("]"sv); + temp.back() = s(temp.back().front() == '[' ? "[ "sv : "["sv) + temp.back() + s("]"sv); break; case id(): transformDoubleString(static_cast(key), temp); @@ -3873,10 +3873,19 @@ private: temp.push_back(s("\""sv) + str + s("\""sv)); break; } - case id(): + case id(): { transformExp(static_cast(content), temp, ExpUsage::Closure); - temp.back() = s("tostring("sv) + temp.back() + s(")"sv); + std::string tostr("tostring"sv); + temp.back() = tostr + '(' + temp.back() + s(")"sv); + if (_config.lintGlobalVariable) { + if (!isDefined(tostr)) { + if (_globals.find(tostr) == _globals.end()) { + _globals[tostr] = {content->m_begin.m_line, content->m_begin.m_col}; + } + } + } break; + } default: assert(false); break; } } -- cgit v1.2.3-55-g6feb