groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
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 GMT
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 <paulk@asert.com.au>
Authored: Sat Aug 25 23:35:11 2018 +1000
Committer: Paul King <paulk@asert.com.au>
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 extends Number> XX foo(Class<XX> 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))
+    }
+}


Mime
View raw message