<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><br class=""></div></div></div><div><blockquote type="cite" class=""><div class="">27 авг. 2019 г., в 15:25, Vladimir Davydov <<a href="mailto:vdavydov.dev@gmail.com" class="">vdavydov.dev@gmail.com</a>> написал(а):</div><br class="Apple-interchange-newline"><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">On Tue, Aug 27, 2019 at 03:10:47PM +0300, Serge Petrenko wrote:</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class=""><blockquote type="cite" class="">27 авг. 2019 г., в 15:04, Vladimir Davydov <<a href="mailto:vdavydov.dev@gmail.com" class="">vdavydov.dev@gmail.com</a>> написал(а):<br class=""><br class="">On Tue, Aug 27, 2019 at 02:22:09PM +0300, Serge Petrenko wrote:<br class=""><blockquote type="cite" class="">This problem is similar to the one fixed in commit<br class="">3c6c1cc96a1a510493c21c472565d4063e403ba2 (lua:fix decimal comparison<br class="">with nil)<br class="">We should handle box.NULL the same way.<br class=""><br class="">Closes #4454<br class="">---<br class=""><a href="https://github.com/tarantool/tarantool/issues/4454" class="">https://github.com/tarantool/tarantool/issues/4454</a><br class="">https://github.com/tarantool/tarantool/tree/sp/gh-4454-decimal-cmp-null<br class=""><br class="">src/lua/decimal.c         |  3 ++-<br class="">test/app/decimal.result   | 30 ++++++++++++++++++++++++++++++<br class="">test/app/decimal.test.lua |  8 ++++++++<br class="">3 files changed, 40 insertions(+), 1 deletion(-)<br class=""><br class="">diff --git a/src/lua/decimal.c b/src/lua/decimal.c<br class="">index 23e50ba68..8905a0b9d 100644<br class="">--- a/src/lua/decimal.c<br class="">+++ b/src/lua/decimal.c<br class="">@@ -235,7 +235,8 @@ static int<br class="">ldecimal_eq(struct lua_State *L)<br class="">{<br class=""><span class="Apple-tab-span" style="white-space: pre;">       </span>assert(lua_gettop(L) == 2);<br class="">-<span class="Apple-tab-span" style="white-space: pre;"> </span>if (lua_isnil(L, 1) || lua_isnil(L, 2)) {<br class="">+<span class="Apple-tab-span" style="white-space: pre;">   </span>if (lua_isnil(L, 1) || lua_isnil(L, 2) ||<br class="">+<span class="Apple-tab-span" style="white-space: pre;">   </span><span class="Apple-converted-space"> </span>   luaL_isnull(L, 1) || luaL_isnull(L, 2)) {<br class=""><span class="Apple-tab-span" style="white-space: pre;">   </span><span class="Apple-tab-span" style="white-space: pre;">  </span>lua_pushboolean(L, false);<br class=""><span class="Apple-tab-span" style="white-space: pre;">   </span><span class="Apple-tab-span" style="white-space: pre;">  </span>return 1;<br class=""><span class="Apple-tab-span" style="white-space: pre;">    </span>}<br class="">diff --git a/test/app/decimal.result b/test/app/decimal.result<br class="">index 8251e13d8..90d0984b0 100644<br class="">--- a/test/app/decimal.result<br class="">+++ b/test/app/decimal.result<br class="">@@ -248,6 +248,36 @@ a <= nil<br class="">| ---<br class="">| - error: '[string "return a <= nil "]:1: attempt to compare decimal with nil'<br class="">| ...<br class="">+-- and with box.NULL<br class="">+--<br class="">+a == box.NULL<br class="">+ | ---<br class="">+ | - false<br class="">+ | ...<br class="">+a ~= box.NULL<br class="">+ | ---<br class="">+ | - true<br class="">+ | ...<br class="">+a > box.NULL<br class="">+ | ---<br class="">+ | - error: '[string "return a > box.NULL "]:1: expected decimal, number or string as<br class="">+ |     1 argument'<br class="">+ | ...<br class=""></blockquote><br class="">1 argument?<br class=""></blockquote><br class="">1st argument<br class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">+a < box.NULL<br class="">+ | ---<br class="">+ | - error: '[string "return a < box.NULL "]:1: expected decimal, number or string as<br class="">+ |     2 argument'<br class="">+ | ...<br class=""></blockquote><br class="">2 argument?<br class=""></blockquote><br class="">2nd argument<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">But in both cases box.NULL is the second argument, isn't it?</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Anyway, looks like it's a different issue, because I get the same</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">confusing error message while trying to compare a decimal with, say,</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">a string. We can fix it in a separate patch if we need to.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div></blockquote><div><br class=""></div>Ah, I see. Sorry for the misunderstanding.</div><div>Yes, here’s the reason for it:</div><div>(an extract from <a href="https://www.lua.org/manual/5.1/manual.html" class="">https://www.lua.org/manual/5.1/manual.html</a>)</div><span class="">`a >= b is equivalent to b <= a. Note that, in the absence of a "le" metamethod, Lua tries the "lt", assuming that a <= b is equivalent to not (b < a).`</span><span class=""><br class="">`a > b is equivalent to b < a.`<br class=""><br class="">So, a > box.NULL actually calls `decimal_lt(box.NULL, a)`. That’s why argument numbers get messed up.</span><div class=""><span class="">AFAIR you don’t have `__gt` and `__ge` metamethods in lua. I guess we should just get rid of argument numbers,</span></div><div class=""><span class="">in error messages here, because I don’t see how this can be fixed otherwise.<br class=""><br class=""><blockquote type="cite" class=""><br class="">Pushed the patch to the master branch as is.<br class=""></blockquote><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><span class=""><br class=""></span></div><div class=""><span class=""><br class=""></span></div></span><div>--</div><div>Serge Petrenko</div><div><a href="mailto:sergepetrenko@tarantool.org" class="">sergepetrenko@tarantool.org</a></div><div class=""><br class=""></div><span class=""><br class=""></span></div></body></html>