From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 4FFED6EC40; Fri, 13 Aug 2021 23:14:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4FFED6EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628885640; bh=hiAdkzBOnLQrxXpafRalUKSglNCs7pVZPgf5QPpo8ig=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=nSr5BQ78umoQJ5gidDM9hKrpVATz/3G6cIKkfrUh4LFzymVXho7smz6FxF6h0NSmf 78iQLm02MPuSH+wvz01nyEolBxQUJNP75yWKNEbGOeT23EjYOxnOqFujZO7plMfMgT /9UG45xK3t8m3EQUI9PQkl1BtDvtmbKoyCVt6Z5s= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 6E2D06EC40 for ; Fri, 13 Aug 2021 23:13:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6E2D06EC40 Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1mEdYz-0003Sv-6q; Fri, 13 Aug 2021 23:13:57 +0300 To: Serge Petrenko , vdavydov@tarantool.org, sergos@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <3a954f7793e6356cefb8cd0151a6434382ec876c.1628810253.git.sergepetrenko@tarantool.org> <9b40f22d-49ad-23fb-35f8-3187612d9086@tarantool.org> Message-ID: Date: Fri, 13 Aug 2021 23:13:56 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <9b40f22d-49ad-23fb-35f8-3187612d9086@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9736CF3E71F18CE0C3E1D5927724F4AAA182A05F538085040087DE09403BE7BFB1006D82598C0BE271FAF0812008788372BC31CAEA4B06E15 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E4A9B39A8BCE3A99EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637822A0A225AD602F38638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B631B470343D92D6C4C76210EEA00F03117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE0AC5B80A05675ACD1AB2475877E8919AD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3A7DFDF579AB090EF03F1AB874ED89028C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637149D0840703ADBE5EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D94463893BF8742D004CE3EA3A46F14B9 X-C1DE0DAB: 0D63561A33F958A55F47109468B5CF6EDB513BEEE24ED283C59DECC21CAE366CD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA750E14360347543F58410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AF12ADB97C97CD89BA9CC68075F4FD2A6A68BF352DEDB439166F6691CC9964AE00CAB2D6854533E91D7E09C32AA3244C363A1FDF158B7FEB18FC3D019EB84789435BF7150578642F927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj0dLV0c3jbkwxwHKxwObHYA== X-Mailru-Sender: 583F1D7ACE8F49BD1042885CEC987B6B96CC4D636BDC3C081006D82598C0BE277B0B9A7C4E99E59B7019711D9D5B048E1458020726E2BC9FD5ECBA0B92C0A936CDC7563AA7CEBD287402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 1/2] lua: introduce table.equals method X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Oleg Babin via Tarantool-patches Reply-To: Oleg Babin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for your fixes. Seems I found one more issue. ``` mt = {__eq = function(a, b) return a.a == b.a end} t1 = setmetatable({a = 3}, mt) t2 = setmetatable({a = 3}, mt) tarantool> t1 == t2 -- metamethod is triggered --- - true ... tarantool> t1 == {a = 3} -- tables have different metatables --- - false ... tarantool> {a = 3} == t1 --- - false ... tarantool> table.equals(t1, t2) -- OK --- - true ... tarantool> table.equals(t1, {a = 3}) -- Seems also ok --- - false ... tarantool> table.equals({a = 3}, t1) -- It's strange --- - true ... ``` Seems you can use two tables if they have the same metatable. Probably here it's described better https://stackoverflow.com/questions/32637684/equality-operator-on-mixed-types-in-lua On 13.08.2021 13:22, Serge Petrenko wrote: > > > 13.08.2021 08:30, Oleg Babin пишет: >> Thanks for your patch. >> >> >> It seems it works in quite strange way: >> >> ``` >> >> tarantool> table.equals({a = box.NULL}, {}) >> --- >> - true >> ... >> >> tarantool> table.equals({}, {a = box.NULL}) >> --- >> - false >> ... >> >> ``` >> >> >> I can change arguments order to get different result. Expected false >> in both cases. >> >> For tap it was considered as buggy behaviour >> https://github.com/tarantool/tarantool/issues/4125 >> >> > > ==================================== > > Good catch! Thanks! > > Check out the diff: > > diff --git a/src/lua/table.lua b/src/lua/table.lua > index 5f35a30f6..3d5e69e97 100644 > --- a/src/lua/table.lua > +++ b/src/lua/table.lua > @@ -63,7 +63,7 @@ end >  -- @return true when the two tables are equal (false otherwise). >  local function table_equals(a, b) >      if type(a) ~= 'table' or type(b) ~= 'table' then > -        return a == b > +        return type(a) == type(b) and a == b >      end >      local mt = getmetatable(a) >      if mt and mt.__eq then > diff --git a/test/app-tap/table.test.lua b/test/app-tap/table.test.lua > index a3c9aa123..ec81593f3 100755 > --- a/test/app-tap/table.test.lua > +++ b/test/app-tap/table.test.lua > @@ -8,7 +8,7 @@ yaml.cfg{ >      encode_invalid_as_nil  = true, >  } >  local test = require('tap').test('table') > -test:plan(38) > +test:plan(40) > >  do -- check basic table.copy (deepcopy) >      local example_table = { > @@ -227,6 +227,10 @@ do -- check table.equals >      test:ok(table.equals({}, {}), "table.equals for empty tables") >      test:is(table.equals({}, {1}), false, "table.equals with one > empty table") >      test:is(table.equals({1}, {}), false, "table.equals with one > empty table") > +    test:is(table.equals({key = box.NULL}, {key = nil}), false, > +            "table.equals for box.NULL and nil") > +    test:is(table.equals({key = nil}, {key = box.NULL}), false, > +            "table.equals for box.NULL and nil") >      local tbl_a = { >          first = { >              1, > > ==================================== >> On 13.08.2021 02:30, Serge Petrenko via Tarantool-patches wrote: >>> Introduce table.equals for comparing tables. >>> The method respects __eq metamethod, if provided. >>> >>> Needed-for #5894 >>> --- >>> >