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 27A96200B7E for ; Tue, 2 Aug 2016 01:14:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 26849160A6C; Mon, 1 Aug 2016 23:14:13 +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 7711C160AA7 for ; Tue, 2 Aug 2016 01:14:12 +0200 (CEST) Received: (qmail 65446 invoked by uid 500); 1 Aug 2016 23:14:11 -0000 Mailing-List: contact commits-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 commits@groovy.apache.org Received: (qmail 65432 invoked by uid 99); 1 Aug 2016 23:14:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Aug 2016 23:14:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6BD26E0B40; Mon, 1 Aug 2016 23:14:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: paulk@apache.org To: commits@groovy.apache.org Date: Mon, 01 Aug 2016 23:14:11 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] groovy git commit: GROOVY-7774: Collection addAll fails CompileStatic type checking when adding a collection of subtypes archived-at: Mon, 01 Aug 2016 23:14:13 -0000 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 Authored: Sat Jul 30 15:31:50 2016 +1000 Committer: paulk 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 boolean addAll(Collection self, Iterator items) { + public static boolean addAll(Collection self, Iterator 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 boolean addAll(Collection self, Iterable items) { + public static boolean addAll(Collection self, Iterable 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 set = new HashSet() + List addIterable = [new Y()] + Iterator addIterator = [new Y()].iterator() + Y[] addArray = [new Y()] + set.addAll(addIterable) + set.addAll(addIterator) + set.addAll(addArray) + assert set.size() == 3 + } + + create() + ''' + } +}