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 A4817200B52 for ; Mon, 25 Jul 2016 10:48:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A3063160A8F; Mon, 25 Jul 2016 08:48:55 +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 EC42C160A78 for ; Mon, 25 Jul 2016 10:48:54 +0200 (CEST) Received: (qmail 51819 invoked by uid 500); 25 Jul 2016 08:48: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 51808 invoked by uid 99); 25 Jul 2016 08:48:53 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jul 2016 08:48:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 730521A5C53 for ; Mon, 25 Jul 2016 08:48:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.72 X-Spam-Level: X-Spam-Status: No, score=-0.72 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=asert-com-au.20150623.gappssmtp.com Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id aaYcf2Pumg69 for ; Mon, 25 Jul 2016 08:48:49 +0000 (UTC) Received: from mail-it0-f46.google.com (mail-it0-f46.google.com [209.85.214.46]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTPS id 2D1A15FB37 for ; Mon, 25 Jul 2016 08:48:48 +0000 (UTC) Received: by mail-it0-f46.google.com with SMTP id f6so79560214ith.1 for ; Mon, 25 Jul 2016 01:48:48 -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=vS+BJkiWwsCMjXO6Pq22f/MYg9g8c2pGz1HlJqIidXs=; b=0SBiWv98DFmTW9zeVCdIrdDXiCY5yoCyyQrIJjUIaETUa6BtczljfB1vn29cwWqpS/ 8TDR6k1cHeypmUm9AGA1KxHmbJI0oxkJ+IVxrIwxsp9+w4ScjPS0sIxYyi9di/NRwi0S Z3ZFxtEu0U92o5BueqS+i6X0LcC2MCZ0lVTeTi0d0E1ycOwIOvJeGAOi2OZDqvcX794M es8cCVcPctrwgcuMIuBKOIuexNmCIuS1DUmhRl24t2En0GrpwcuslUxK/ZZgM2+NOb2m 3bOpoJH5HzhQhOsMJHkPYJPzHP9gh/3fCYtaGh4EJaRJn2am6KzNFNpPGNQpjyt6vVV8 pzYQ== 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=vS+BJkiWwsCMjXO6Pq22f/MYg9g8c2pGz1HlJqIidXs=; b=Tj4R6vlN3KW2h+/Psuna3tK4kV+1Sef6/vEX4PPnG3a0zUVh+KznO5yJDUn3RIdWoj fkm0bLN587AKgEAbSnxNvdJ4zGLMpZYxENJt62RJUd93iya/CpIl1CSRpYVbKnRgiD8V lp1msgkrGPIq38hFx5RpRLiKKrBPj2m9Qs+jHDuXoP+dRZbMTXilu4Aw4Yctz6pksOV6 qG/I5IwlgCs/fQjOG2qIGPGufC2FB4OVScIwc4qMP13JpywstvYS79lESWGtF1tZDWX7 SeAJ0+geamzIk4+7WxiQY7Z8seBPUqbDjlRzmPTAuVxMDMJZ4OA73qel3RiXBrCwS9Mn SGeQ== X-Gm-Message-State: ALyK8tJ1WI/QCTpB/CfTl2XeqowUxE4Zp5DhmYwSXutEblCRvftAMXuo0SQqypxLXpb915FIVQcyZF1zRnaH4Q== X-Received: by 10.36.252.193 with SMTP id b184mr70972328ith.4.1469436521811; Mon, 25 Jul 2016 01:48:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.129.159 with HTTP; Mon, 25 Jul 2016 01:48:41 -0700 (PDT) Reply-To: paulk@asert.com.au In-Reply-To: <5795BA27.9000808@gmx.org> References: <2e32e62080694924bfbc444e266f5421@git.apache.org> <5791F59B.9070101@gmx.org> <57921D09.4020201@gmx.org> <5795BA27.9000808@gmx.org> From: Paul King Date: Mon, 25 Jul 2016 18:48:41 +1000 Message-ID: Subject: Re: groovy git commit: GROOVY-7876: ClassCastException when calling DefaultTypeTransformation#compareEqual (closes #368) To: dev@groovy.apache.org Content-Type: text/plain; charset=UTF-8 archived-at: Mon, 25 Jul 2016 08:48:55 -0000 Yes, I generally agree with what you are suggesting. We do seem to talk about this a lot from time to time but struggle to make much real progress. I guess we need to start filling in the parts of this puzzle with poorly defined behavior with some additional tests. I'll try to give some more attention to some of the outstanding PRs around custom numbers if I get time. Cheers, Paul. On Mon, Jul 25, 2016 at 5:05 PM, Jochen Theodorou wrote: > On 24.07.2016 14:56, Paul King wrote: >> >> I think the GString check can be moved up as you suggest to improve >> the readability of the code without breaking existing behavior, so >> I've done that. >> >> Whether to go with your other suggestions is less clear to me. >> >> If we assume the check in EqualsTest#testParentChildrenEquals remains >> valid, i.e. we want symmetry of equals for java.util.Date and >> java.sql.Time which compareTo gives us so long as we have both the >> left<> in master seems reasonable. And once we have the right<> need the Object check as well for GROOVY-4046. > > > If we do this only for java.util.Date and family, then we should probably > special case it much like we do for GString > > [...] >> >> I guess the underlying assumption in the existing code is that for >> Comparable classes, the compareTo method is more likely to provide a >> "business/human" friendly equality check than equals (since the >> contracts around equals behavior have more specific strict >> requirements), as illustrated by e.g. BigDecimal. The question is >> then, do we want to continue honoring this assumption or provide that >> only for the specific number widening that we do anyway. >> >> So, if we want to change the code to something like: >> >> if (equalityCheckOnly) { >> return left.equals(right) ? 0 : -1; >> } else { >> return ((Comparable) left).compareTo(right); >> } >> >> then something like the following could no longer be made to work: >> >> class NumberHolder implements Comparable { >> Number n >> int compareTo(NumberHolder other) { >> n <=> other.n >> } >> } >> >> assert new NumberHolder(n: 10L) == new NumberHolder(n: 10.0G) >> >> For me, such a breaking change sounds more like a 3.0 thing. > > > My suggestions means more or less to make == go to equals and <=> to > compareTo, of course more according to our special rules and including some > widening and stuff.. But this implementation would be more near Java in my > eyes, while still being comfortable enough. > > For 2.0 I would see two more ways: > (a) define our own method for to do any of <,<=,==,<=>,>=,>. With the > problem of having to have a fallback, that depends on equals and compareTo > and most likely will have the same problem, plus the problem of not being so > Java friendly. > (b) have an equals == and a compareTo ==, with differing syntax... maybe > time to resurrect === and have <, <=, ===, <=>, >=, > ... well, or any other > operator we can come up with... > > bye Jochen