Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check for warning comments in actual comment bodies #979

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/llex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ static void inclinenumber (LexState *ls) {
if (currIsNewline(ls) && ls->current != old)
next(ls); /* skip '\n\r' or '\r\n' */

const std::string& buff = ls->getLineBuff();
if (buff.find("@pluto_warnings") != std::string::npos)
ls->lexPushWarningOverride().processComment(buff);

ls->lines.emplace_back(std::string{});
}

Expand Down Expand Up @@ -423,9 +419,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
}
}
} endloop:
if (seminfo)
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
luaZ_bufflen(ls->buff) - sep - 1);
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + 1,
luaZ_bufflen(ls->buff) - sep - 1);
}


Expand Down Expand Up @@ -603,8 +598,11 @@ static int llex (LexState *ls, SemInfo *seminfo, int *column) {
if (sep >= 2) {
ls->appendLineBuff(sep - 2, '=');
ls->appendLineBuff('[');
read_long_string(ls, nullptr, sep); /* skip long comment */
SemInfo si;
read_long_string(ls, &si, sep); /* skip long comment */
luaZ_resetbuffer(ls->buff); /* 'read_long_string' may dirty the buffer */
if (strstr(getstr(si.ts), "@pluto_warnings") != nullptr)
ls->lexPushWarningOverride().processComment(getstr(si.ts));
ls->appendLineBuff(']');
ls->appendLineBuff(sep - 2, '=');
ls->appendLineBuff(']');
Expand All @@ -620,19 +618,21 @@ static int llex (LexState *ls, SemInfo *seminfo, int *column) {
}
if (ls->current == '@') { /* attribute? */
ls->appendLineBuff('@');
next(ls);
save_and_next(ls);
while (lislalnum(ls->current))
save_and_next(ls);
ls->appendLineBuff(luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff));
if (strncmp(luaZ_buffer(ls->buff), "pluto_use", luaZ_bufflen(ls->buff)) == 0) {
return TK_USEANN;
}
luaZ_resetbuffer(ls->buff);
}
while (!currIsNewline(ls) && ls->current != EOZ) {
ls->appendLineBuff(ls->current);
next(ls); /* skip until end of line (or end of file) */
save_and_next(ls); /* skip until end of line (or end of file) */
}
if (strstr(luaZ_buffer(ls->buff), "@pluto_warnings") != nullptr)
ls->lexPushWarningOverride().processComment(luaZ_buffer(ls->buff));
luaZ_resetbuffer(ls->buff);
if (ls->getLineBuff().find("@fallthrough") != std::string::npos)
return TK_FALLTHROUGH;
break;
Expand Down
18 changes: 9 additions & 9 deletions src/llex.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ class WarningConfig
}
}

void processComment(const std::string& line) noexcept {
void processComment(const char* line) noexcept {
for (int id = 0; id != NUM_WARNING_TYPES; ++id) {
const std::string& name = luaX_warnNames[id];
if (line.find(name) == std::string::npos)
const char* name = luaX_warnNames[id];
if (strstr(line, name) == nullptr)
continue;

std::string enable = "enable-";
Expand All @@ -310,18 +310,18 @@ class WarningConfig
disable += name;
error += name;

if (line.find(enable) != std::string::npos) {
if (name != "all")
if (strstr(line, enable.c_str()) != nullptr) {
if (id != ALL_WARNINGS)
states[id] = WS_ON;
else
setAllTo(WS_ON);
} else if (line.find(disable) != std::string::npos) {
if (name != "all")
} else if (strstr(line, disable.c_str()) != nullptr) {
if (id != ALL_WARNINGS)
states[id] = WS_OFF;
else
setAllTo(WS_OFF);
} else if (line.find(error) != std::string::npos) {
if (name != "all")
} else if (strstr(line, error.c_str()) != nullptr) {
if (id != ALL_WARNINGS)
states[id] = WS_ERROR;
else
setAllTo(WS_ERROR);
Expand Down
11 changes: 10 additions & 1 deletion testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ do
end
end]]
end
-- Strings should not be able to disable warnings
do
assert_warn[[assert("@pluto_warnings: disable-all")

local x
local x]]
end

print "Testing assertion library."
do
Expand Down Expand Up @@ -1421,6 +1428,7 @@ do
assert(("69") |> tonumber|16| == 0x69)

-- Try to avoid syntax ambiguity by not allowing function call with '(' in the chain after pipe operator was used.
-- @pluto_warnings disable-next
;(69) |> f (69) |> f

-- Other types of function calls are still okay, tho, since string and table are not valid statements.
Expand Down Expand Up @@ -2183,7 +2191,7 @@ do
e = bigint.new(0x10001),
}

local enc = crypto.encrypt("Hi", "rsa", pub)
enc = crypto.encrypt("Hi", "rsa", pub)
assert(base64.encode(enc) == "w1v3stxRHCs=")
assert(crypto.decrypt(enc, "rsa", priv) == "Hi")

Expand Down Expand Up @@ -3309,6 +3317,7 @@ do
-- Export in try body
local function f()
try
-- @pluto_warnings disable-next (export is deprecated)
export function a() end
catch e then
end
Expand Down