From commits-return-7347-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Sun Aug 26 03:18:31 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 9F6FC180654 for ; Sun, 26 Aug 2018 03:18:30 +0200 (CEST) Received: (qmail 15953 invoked by uid 500); 26 Aug 2018 01:18:29 -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 15944 invoked by uid 99); 26 Aug 2018 01:18:29 -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; Sun, 26 Aug 2018 01:18:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7584ADFB32; Sun, 26 Aug 2018 01:18:29 +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 Message-Id: <197a3b896aa54a9e9330e97686f97fd9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: groovy git commit: GROOVY-8757: Incorrect bytecode produced after compiling class implementing trait with generic method (closes #788) Date: Sun, 26 Aug 2018 01:18:29 +0000 (UTC) Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 6c615579f -> 5a1807d9c GROOVY-8757: Incorrect bytecode produced after compiling class implementing trait with generic method (closes #788) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5a1807d9 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5a1807d9 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5a1807d9 Branch: refs/heads/GROOVY_2_5_X Commit: 5a1807d9cc2127b9ea8f1de1cf91355f9719527f Parents: 6c61557 Author: Paul King Authored: Sat Aug 25 23:35:11 2018 +1000 Committer: Paul King Committed: Sun Aug 26 11:18:18 2018 +1000 ---------------------------------------------------------------------- .../groovy/ast/tools/GenericsUtils.java | 18 +++++++++++- src/test/groovy/bugs/groovy8757/T0.groovy | 25 ++++++++++++++++ .../groovy/bugs/groovy8757/UsageTest.groovy | 31 ++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/5a1807d9/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 9211543..21d654b 100644 --- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java +++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java @@ -460,7 +460,23 @@ public class GenericsUtils { GenericsType[] sgts = current.getGenericsTypes(); if (sgts != null) { for (GenericsType sgt : sgts) { - ret.put(sgt.getName(), sgt.getType()); + String name = sgt.getName(); + if (sgt.isPlaceholder()) { + ClassNode redirect; + if (sgt.getUpperBounds() != null) { + redirect = sgt.getUpperBounds()[0]; + } else if (sgt.getLowerBound() != null) { + redirect = sgt.getLowerBound(); + } else { + redirect = ClassHelper.OBJECT_TYPE; + } + ClassNode type = ClassHelper.makeWithoutCaching(name); + type.setGenericsPlaceHolder(true); + type.setRedirect(redirect); + ret.put(name, type); + } else { + ret.put(name, sgt.getType()); + } } } return ret; http://git-wip-us.apache.org/repos/asf/groovy/blob/5a1807d9/src/test/groovy/bugs/groovy8757/T0.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/bugs/groovy8757/T0.groovy b/src/test/groovy/bugs/groovy8757/T0.groovy new file mode 100644 index 0000000..d614e27 --- /dev/null +++ b/src/test/groovy/bugs/groovy8757/T0.groovy @@ -0,0 +1,25 @@ +/* + * 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.groovy8757 + +trait T0 { + def XX foo(Class c) { + c.newInstance(42) + } +} http://git-wip-us.apache.org/repos/asf/groovy/blob/5a1807d9/src/test/groovy/bugs/groovy8757/UsageTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/bugs/groovy8757/UsageTest.groovy b/src/test/groovy/bugs/groovy8757/UsageTest.groovy new file mode 100644 index 0000000..321820e --- /dev/null +++ b/src/test/groovy/bugs/groovy8757/UsageTest.groovy @@ -0,0 +1,31 @@ +/* + * 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.groovy8757 + +class UsageTest extends GroovyTestCase { + void testAccessingPrecompiledTraitWithMethodGenerics() { + def c0 = new GroovyShell().evaluate(''' + import groovy.bugs.groovy8757.T0 + class C0 implements T0 {} + new C0() + ''') + assertEquals(42, c0.foo(Integer)) + assertEquals(42L, c0.foo(Long)) + } +}