From commits-return-6476-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Fri May 11 08:08:29 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 486B1180647 for ; Fri, 11 May 2018 08:08:29 +0200 (CEST) Received: (qmail 22690 invoked by uid 500); 11 May 2018 06:08:28 -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 22680 invoked by uid 99); 11 May 2018 06:08:28 -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; Fri, 11 May 2018 06:08:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2E991E09EC; Fri, 11 May 2018 06:08:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: groovy git commit: GROOVY-7985: Wrong "incompatible generic type" error Date: Fri, 11 May 2018 06:08:28 +0000 (UTC) Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 57cfd2a3e -> 8f60b4826 GROOVY-7985: Wrong "incompatible generic type" error (cherry picked from commit 9f14993) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8f60b482 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8f60b482 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8f60b482 Branch: refs/heads/GROOVY_2_5_X Commit: 8f60b482682aeba8cdf7a5d63b39585ccb7e1a65 Parents: 57cfd2a Author: sunlan Authored: Fri May 11 14:04:57 2018 +0800 Committer: sunlan Committed: Fri May 11 14:08:23 2018 +0800 ---------------------------------------------------------------------- .../groovy/ast/tools/GenericsUtils.java | 33 +++++++---- src/test/groovy/bugs/Groovy7985Bug.groovy | 62 ++++++++++++++++++++ 2 files changed, 82 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/8f60b482/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java index 98057d0..27f2bd9 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java @@ -165,6 +165,8 @@ public class GenericsUtils { "\nExpected: " + node.getName() + toGenericTypesString(redirectGenericsTypes) + "\nSupplied: " + node.getName() + toGenericTypesString(parameterized)); } + + List valueList = new LinkedList<>(); for (int i = 0; i < redirectGenericsTypes.length; i++) { GenericsType redirectType = redirectGenericsTypes[i]; if (redirectType.isPlaceholder()) { @@ -172,21 +174,26 @@ public class GenericsUtils { if (!map.containsKey(name)) { GenericsType value = parameterized[i]; map.put(name, value); - if (value.isWildcard()) { - ClassNode lowerBound = value.getLowerBound(); - if (lowerBound != null) { - extractPlaceholders(lowerBound, map); - } - ClassNode[] upperBounds = value.getUpperBounds(); - if (upperBounds != null) { - for (ClassNode upperBound : upperBounds) { - extractPlaceholders(upperBound, map); - } - } - } else if (!value.isPlaceholder()) { - extractPlaceholders(value.getType(), map); + + valueList.add(value); + } + } + } + + for (GenericsType value : valueList) { + if (value.isWildcard()) { + ClassNode lowerBound = value.getLowerBound(); + if (lowerBound != null) { + extractPlaceholders(lowerBound, map); + } + ClassNode[] upperBounds = value.getUpperBounds(); + if (upperBounds != null) { + for (ClassNode upperBound : upperBounds) { + extractPlaceholders(upperBound, map); } } + } else if (!value.isPlaceholder()) { + extractPlaceholders(value.getType(), map); } } } http://git-wip-us.apache.org/repos/asf/groovy/blob/8f60b482/src/test/groovy/bugs/Groovy7985Bug.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/bugs/Groovy7985Bug.groovy b/src/test/groovy/bugs/Groovy7985Bug.groovy new file mode 100644 index 0000000..e0b45b5 --- /dev/null +++ b/src/test/groovy/bugs/Groovy7985Bug.groovy @@ -0,0 +1,62 @@ +/* + * 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 + +class Groovy7985Bug extends GroovyTestCase { + void test1() { + assertScript ''' + import java.io.Serializable; + import java.util.Date; + import groovy.transform.CompileStatic + + @CompileStatic + class Test { + Pair, Pair> doSmething() { + def left = (Pair) Pair.of("a", 1) + def right = (Pair) Pair.of("b", 2) + return Pair.of(left, right) + } + } + + @CompileStatic + class Pair implements Serializable { + public static Pair of(final L left, final R right) { + return new Pair<>(left, right); + } + + public final L left; + public final R right; + + private Pair(final L left, final R right) { + this.left = left; + this.right = right; + } + } + + assert 'a' == new Test().doSmething().left.left + assert 1 == new Test().doSmething().left.right + assert 'b' == new Test().doSmething().right.left + assert 2 == new Test().doSmething().right.right + ''' + } +}