groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/2] groovy git commit: GROOVY-7774: Collection addAll fails CompileStatic type checking when adding a collection of subtypes
Date Mon, 01 Aug 2016 23:14:11 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 6778128eb -> ca97826de


GROOVY-7774: Collection addAll fails CompileStatic type checking when adding a collection
of subtypes


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/002f85e9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/002f85e9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/002f85e9

Branch: refs/heads/GROOVY_2_4_X
Commit: 002f85e920594aef9f60bc4de44a29d00329125b
Parents: 6778128
Author: paulk <paulk@asert.com.au>
Authored: Sat Jul 30 15:31:50 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Tue Aug 2 09:13:56 2016 +1000

----------------------------------------------------------------------
 .../groovy/runtime/DefaultGroovyMethods.java    |  4 +-
 .../groovy/transform/stc/Groovy7774Bug.groovy   | 42 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/002f85e9/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 53b406d..f5582d5 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -9368,7 +9368,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      * @param items the items to add
      * @return true if the collection changed
      */
-    public static <T> boolean addAll(Collection<T> self, Iterator<T> items)
{
+    public static <T> boolean addAll(Collection<T> self, Iterator<? extends
T> items) {
         boolean changed = false;
         while (items.hasNext()) {
             T next =  items.next();
@@ -9384,7 +9384,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
      * @param items the items to add
      * @return true if the collection changed
      */
-    public static <T> boolean addAll(Collection<T> self, Iterable<T> items)
{
+    public static <T> boolean addAll(Collection<T> self, Iterable<? extends
T> items) {
         boolean changed = false;
         for (T next : items) {
             if (self.add(next)) changed = true;

http://git-wip-us.apache.org/repos/asf/groovy/blob/002f85e9/src/test/groovy/transform/stc/Groovy7774Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/Groovy7774Bug.groovy b/src/test/groovy/transform/stc/Groovy7774Bug.groovy
new file mode 100644
index 0000000..ca9b1ab
--- /dev/null
+++ b/src/test/groovy/transform/stc/Groovy7774Bug.groovy
@@ -0,0 +1,42 @@
+/*
+ *  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.transform.stc
+
+class Groovy7774Bug extends StaticTypeCheckingTestCase {
+    void testCollectionAddAllShouldHonorInheritance() {
+        assertScript '''
+            class X{}
+            class Y extends X{}
+
+            def create() {
+              Set<X> set = new HashSet<X>()
+              List<Y> addIterable = [new Y()]
+              Iterator<Y> addIterator = [new Y()].iterator()
+              Y[] addArray = [new Y()]
+              set.addAll(addIterable)
+              set.addAll(addIterator)
+              set.addAll(addArray)
+              assert set.size() == 3
+            }
+
+            create()
+        '''
+    }
+}


Mime
View raw message