You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/01/27 22:39:49 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-9911: Tuples with same collection values do not match

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 52e852f  GROOVY-9911: Tuples with same collection values do not match
52e852f is described below

commit 52e852f62a71b28848545a59c67e8930d485b2f3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Jan 28 00:48:56 2021 +1000

    GROOVY-9911: Tuples with same collection values do not match
---
 src/main/java/groovy/lang/Tuple.java   |  7 +++++--
 src/test/groovy/bugs/Groovy9911.groovy | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/main/java/groovy/lang/Tuple.java b/src/main/java/groovy/lang/Tuple.java
index 4e06ab1..da8f31e 100644
--- a/src/main/java/groovy/lang/Tuple.java
+++ b/src/main/java/groovy/lang/Tuple.java
@@ -114,10 +114,13 @@ public class Tuple<E> extends AbstractList<E> implements Serializable, Cloneable
                 ? 1
                 : t2 == null
                 ? -1
-                : ((Comparable<T>) t1).compareTo(t2);
+                : t1 instanceof Comparable
+                ? ((Comparable<T>) t1).compareTo(t2)
+                : DefaultTypeTransformation.compareEqual(t1, t2)
+                ? 0
+                : 1;
     }
 
-
     /**
      * Construct a tuple of degree 0.
      */
diff --git a/src/test/groovy/bugs/Groovy9911.groovy b/src/test/groovy/bugs/Groovy9911.groovy
new file mode 100644
index 0000000..7d07e48
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9911.groovy
@@ -0,0 +1,28 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import org.junit.Test
+
+final class Groovy9911 {
+    @Test
+    void testTupleEqualityWithNonComparableElements() {
+        assert Tuple.tuple(1, [2]) == Tuple.tuple(1, [2])
+    }
+}