From e961a16a52d619f263c9909c447ce0908b2accf9 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 8 Feb 2025 23:17:49 +0100 Subject: [PATCH] Improve error message for in expression `"abc" in nil` now says that the second operand could also be a string --- src/lvm.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lvm.cpp b/src/lvm.cpp index bc9ec4b72..447344538 100644 --- a/src/lvm.cpp +++ b/src/lvm.cpp @@ -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));