Skip to content

Commit

Permalink
Improve error message for in expression
Browse files Browse the repository at this point in the history
`"abc" in nil` now says that the second operand could also be a string
  • Loading branch information
Sainan committed Feb 10, 2025
1 parent c668d1b commit e961a16
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,10 @@ static void inopr (lua_State *L, StkId ra, TValue *a, TValue *b) {
}
} else {
if (l_unlikely(!ttistable(b))) {
luaG_runerror(L, "expected second 'in' operand to be table, got %s", ttypename(ttype(b)));
if (ttisstring(a))
luaG_runerror(L, "expected second 'in' operand to be table or string, got %s", ttypename(ttype(b)));
else
luaG_runerror(L, "expected second 'in' operand to be table, got %s", ttypename(ttype(b)));
} else {
if (luaV_searchelement(L, hvalue(b), a)) {
setbtvalue(s2v(ra));
Expand Down

0 comments on commit e961a16

Please sign in to comment.