Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6CE22200BB1 for ; Thu, 3 Nov 2016 07:42:57 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6B731160AFF; Thu, 3 Nov 2016 06:42:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 42F9D160AFE for ; Thu, 3 Nov 2016 07:42:56 +0100 (CET) Received: (qmail 16407 invoked by uid 500); 3 Nov 2016 06:42:54 -0000 Mailing-List: contact dev-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list dev@groovy.apache.org Received: (qmail 16393 invoked by uid 99); 3 Nov 2016 06:42:54 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2016 06:42:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 25F89C07CC for ; Thu, 3 Nov 2016 06:42:54 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.813 X-Spam-Level: *** X-Spam-Status: No, score=3.813 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_SORBS_SPAM=0.5, URIBL_BLOCKED=0.001, URI_HEX=1.313] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=asert-com-au.20150623.gappssmtp.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id WJ0CI3CgOzor for ; Thu, 3 Nov 2016 06:42:51 +0000 (UTC) Received: from mail-oi0-f48.google.com (mail-oi0-f48.google.com [209.85.218.48]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id ACABD5F3F4 for ; Thu, 3 Nov 2016 06:42:50 +0000 (UTC) Received: by mail-oi0-f48.google.com with SMTP id v84so67270149oie.3 for ; Wed, 02 Nov 2016 23:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asert-com-au.20150623.gappssmtp.com; s=20150623; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to; bh=4pFqdQnb1r0asRv+OzowfwZnMChSNeY2tRrs3qwlv6s=; b=fJBDwurK4zoVjyz4verrkwBmkjTW8ol6G0tUsSKW1tVI8t8hH1wKdjuZEktMS1axkY L2HyhMf3QjByUrMQuTY7ejxmPjH+Wwz1n+P0p23zAS0aZoccJtHfFA1Plf67Uiw6OGa3 faCnOYKLgP9GUKrdKfoTitoDGM0q9t0X9luS2Sd74XIYewl801faEsaIcG8WXW3xhLWU 3nTMWmY2qyThOdOQPBbqo85jS+HdlYCZA+qje0AJkjwsnisPX+OA484vwGg11p1EkXaj mzHF/nNgmwth7O+1l/bJQLJo1W96dm3RxnZHdgH51ipthalhZG1pj0ZJFwpJLLIPjeLD XjsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to; bh=4pFqdQnb1r0asRv+OzowfwZnMChSNeY2tRrs3qwlv6s=; b=U7cjR6meptcphDNn7RZ3dG7GLHMYQQkosO97TfXRQhpOLag/DjyD0fb09cFi6zpSX9 1zpzOKB2r82+KmT8I+5s/cAXUcrEriy0P+iIavAuDa6iZzwnmtNbBQ/U7N3BIW8xEFkP W9RgnQ6x3izkU1XZuVgiLDeVsSf+JouGlM+tkTMTdMBau3ygOPXm0Mw0mPiI1bSanllU F+4Ll6DE+6lM5LQeelM8NEVsCRBUZDFg8Zi3e/Qn3x2LlgT1NqjlDQeMJupJtUqXtv3P UPlknyhzmueCcPeKnlkJ+Gha1xmbA/dnIlu7vw6En7hM3oeurcV7Up0TtpuK1tQD2Fwm mxwg== X-Gm-Message-State: ABUngvc6GXQWZMR+V9coHSsbx4RwzFw18zVZqXnLKr5lXkOZFQw1S/QDKeSXa7S88049LxXacaqmC3hbAUd+8Q== X-Received: by 10.36.78.145 with SMTP id r139mr5044931ita.60.1478155368833; Wed, 02 Nov 2016 23:42:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.146.7 with HTTP; Wed, 2 Nov 2016 23:42:48 -0700 (PDT) Reply-To: paulk@asert.com.au In-Reply-To: References: <581457BB.6010306@gmx.org> <1477824644566-5736398.post@n5.nabble.com> From: Paul King Date: Thu, 3 Nov 2016 16:42:48 +1000 Message-ID: Subject: Re: An issue about comparing arrays To: dev@groovy.apache.org Content-Type: multipart/alternative; boundary=001a1139768aaebc3305405fdde7 archived-at: Thu, 03 Nov 2016 06:42:57 -0000 --001a1139768aaebc3305405fdde7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable We just have to be a little careful. Rightly or wrongly (search the mailing lists for many discussions), current Groovy's '=3D=3D' tries to do 'friendl= y coercion' between types to try to give a business domain friendly meaning to equality: String[] one =3D ['a', 'b', 'c'] List two =3D ['a', 'b', 'c'] assert one.class !=3D two.class assert one =3D=3D two int[] ints =3D [1, 2] long[] longs =3D [1L, 2L] assert ints =3D=3D longs So as long as we can tell that we have two things that can't possibly be equal, then we should return false. Cheers, Paul. On Thu, Nov 3, 2016 at 11:38 AM, Daniel.Sun wrote= : > I verified the comparing of Java, which will check the type first. e.g. > > new int[2][][].equals(new int[2][]) // false > new int[2].equals(new long[2]) // false > > Cheers, > Daniel.Sun > > > > =E5=9C=A8 "bo zhang [via Groovy]" >=EF=BC=8C20= 16=E5=B9=B411=E6=9C=883=E6=97=A5 > =E4=B8=8A=E5=8D=889:24=E5=86=99=E9=81=93=EF=BC=9A > > Yes, that's my first instinct too, but a few minutes later I found test > cases as follows: > > assert [[[5, 6], [7, 8]]] as int[][][] =3D=3D [[[5, 6], [7, 8]]] as Long[= ][][] > > See https://github.com/groovy/groovy-core/blob/master/src/ > test/groovy/ArrayTest.groovy#L207 > > I think this issue can be discussed, anybody has opinions? > > 2016-11-03 7:51 GMT+08:00 Daniel.Sun <[hidden email]>: > >> IMO, we should compare their type first. If not same, the comparing >> result should be 'false'. >> >> Cheers, >> Daniel.Sun >> >> >> >> =E5=9C=A8 "bo zhang [via Groovy]" =EF=BC=8C2016= =E5=B9=B411=E6=9C=883=E6=97=A5 06:53=E5=86=99=E9=81=93=EF=BC=9A >> >> I'm afraid it's not a bug. >> >> Actually, `def a=3Dnew int[2][]` means that a is an array of two null >> pointers with type "int []", and `def b=3Dnew int[2][][]` means that b i= s an >> array of two null pointers with type "int[][]", it seems that they shoul= d >> be equal. >> >> See https://github.com/groovy/groovy-core/blob/master/src/ >> test/groovy/ArrayTest.groovy#L198 >> >> >> =E2=80=8B >> >> 2016-10-30 18:50 GMT+08:00 Daniel.Sun <[hidden email]>: >> >>> Hi Jochen, >>> >>> I create JIRA issue >>> GROOVY-7983(https://issues.apache.org/jira/browse/GROOVY-7983) to track >>> the >>> issue. >>> >>> BTW, the code in the email should be corrected as follow: >>> >>> def a =3D new int[2][] >>> def b =3D new int[2][][] >>> assert a =3D=3D b // expect faling >>> >>> Cheers, >>> Daniel.Sun >>> >>> >>> >>> -- >>> View this message in context: http://groovy.329449.n5. >>> nabble.com/An-issue-about-comparing-arrays-tp5736379p5736398.html >>> Sent from the Groovy Dev mailing list archive at Nabble.com. >>> >> >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the discussion >> below: >> http://groovy.329449.n5.nabble.com/An-issue-about-comparing-arrays- >> tp5736379p5736458.html >> To unsubscribe from An issue about comparing arrays, click here. >> NAML >> >> >> >> ------------------------------ >> View this message in context: Re: An issue about comparing arrays >> >> >> Sent from the Groovy Dev mailing list archive >> at >> Nabble.com. >> > > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > http://groovy.329449.n5.nabble.com/An-issue-about-comparing-arrays- > tp5736379p5736461.html > To unsubscribe from An issue about comparing arrays, click here. > NAML > > > > ------------------------------ > View this message in context: Re: An issue about comparing arrays > > Sent from the Groovy Dev mailing list archive > at > Nabble.com. > --001a1139768aaebc3305405fdde7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
We just have to be a little careful. Rightly or wrongly (s= earch the mailing lists for many discussions), current Groovy's '= =3D=3D' tries to do 'friendly coercion' between types to try to= give a business domain friendly meaning to equality:

String[] one =3D ['a', 'b', 'c']
List&= lt;String> two =3D ['a', 'b', 'c']
ass= ert one.class !=3D two.class
assert one =3D=3D two

int[] ints =3D [1, 2]
long[] longs =3D [1L,= 2L]
assert ints =3D=3D longs

So a= s long as we can tell that we have two things that can't possibly be eq= ual, then we should return false.

Cheers, Paul.


On Thu, Nov 3, 2016 at 11:38 AM, Daniel.Sun <realbluesun@hotm= ail.com> wrote:
I verified the comparing of Java, which will check the typ= e first. e.g.

new int[2][][].equals(new int[2][]) // false
new int[2].equals(new long[2]) // false

Cheers,
Daniel.Sun



=E5=9C=A8 "bo zhang [v= ia Groovy]" <ml-node+[hidden email]>=EF=BC=8C2016=E5=B9=B411=E6=9C=883=E6=97= =A5 =E4=B8=8A=E5=8D=889:24=E5=86=99=E9=81=93=EF=BC=9A

Yes, that's my first instinct too, but a few minutes l= ater I found test cases as follows:

assert [[[5, 6], [7, 8]]] as int[][][] =3D=3D [[[5, 6], [7, 8]]] as Long[][][]
=

I think this issue can be discussed, anybody has opinions?

2016-11-03 7:51 GMT+08:00 Daniel.Sun <[hidden email]>:
IMO, we should compare their type first. If not same, the = comparing result should be 'false'.

Cheers,
Daniel.Sun



=E5= =9C=A8 "bo zhang [via Groovy]" <ml-node+[hidden email]>=EF=BC=8C2016=E5=B9=B411=E6=9C=883=E6= =97=A5 06:53=E5=86=99=E9=81=93=EF=BC=9A

I'm afraid it's not a bug.

Actually, `def a=3Dnew int[2][]` means that a is an array of two null = pointers with type "int []", and `def b=3Dnew int[2][][]` means t= hat b is an array of two null pointers with type "int[][]", it se= ems that they should be equal.



=E2=80=8B

2016-10-30 18:50 GMT+08:00 Daniel.Sun <[hidden email]>:
Hi Jochen,

=C2=A0 =C2=A0 =C2=A0I create JIRA issue
GROOVY-7983(https://issues.apa= che.org/jira/browse/GROOVY-7983) to track the
issue.

=C2=A0 =C2=A0 =C2=A0BTW,=C2=A0 the code in the email should be corrected as= follow:

def a =3D new int[2][]
def b =3D new int[2][][]
assert a =3D=3D b // expect faling

Cheers,
Daniel.Sun



--
View this message in context: http://groovy.329449.n5.nabble.com/An-issue-about-comparing-array= s-tp5736379p5736398.html
Sent from the Groovy Dev mailing list archive at Nabble.com.




If you reply to this email, your message wi= ll be added to the discussion below:
http://groovy.329449.n5.nabble.com/An-issue-about-comparing-= arrays-tp5736379p5736458.html
To unsubscribe from An issue about comparing arrays, click here.
NAML


View this message in context: Re: An issue about comparing arrays

Sent from the Groovy Dev mailing list archive at Nabble.com.




If you reply to this email, your message wi= ll be added to the discussion below:
http://groovy.329449.n5.nabble.com/An-issue-about-comparing-arrays-tp5736379p5736461.html
To unsubscribe from An issue about comparing arrays, click here.
NAML
=09 =09 =09

View this message in context: = Re: An issue about comparing arrays
Sent from the Groovy Dev mailing list archive at Nabble.c= om.

--001a1139768aaebc3305405fdde7--