You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/09/13 14:48:10 UTC

[1/2] groovy git commit: Revert "GROOVY-7721: Static type checking fails when compiling against a Java interface call (closes #599)"

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 6e47e6df4 -> ddebbeca2


Revert "GROOVY-7721: Static type checking fails when compiling against a Java interface call (closes #599)"

This reverts commit 34df6cf461a5ecce66f2c2c0f14489cf96feaf34.

(cherry picked from commit 695b7af)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 22635dac48a84152fecc887e5a919efdd52009be
Parents: 6e47e6d
Author: sunlan <su...@apache.org>
Authored: Wed Sep 13 22:35:50 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Wed Sep 13 22:47:48 2017 +0800

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingSupport.java          | 11 +--
 src/test/groovy/bugs/Groovy7721Bug.groovy       | 80 --------------------
 2 files changed, 2 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/22635dac/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index eb208fe..98fb157 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1149,20 +1149,13 @@ public abstract class StaticTypeCheckingSupport {
     private static void removeMethodWithSuperReturnType(List<MethodNode> toBeRemoved, MethodNode one, MethodNode two) {
         ClassNode oneRT = one.getReturnType();
         ClassNode twoRT = two.getReturnType();
-        if (isCovariant(oneRT, twoRT)) {
+        if (oneRT.isDerivedFrom(twoRT) || oneRT.implementsInterface(twoRT)) {
             toBeRemoved.add(two);
-        } else if (isCovariant(twoRT, oneRT)) {
+        } else if (twoRT.isDerivedFrom(oneRT) || twoRT.implementsInterface(oneRT)) {
             toBeRemoved.add(one);
         }
     }
 
-    private static boolean isCovariant(ClassNode left, ClassNode right) {
-        if (left.isArray() && right.isArray()) {
-            return isCovariant(left.getComponentType(), right.getComponentType());
-        }
-        return left.isDerivedFrom(right) || left.implementsInterface(right);
-    }
-
     private static boolean areOverloadMethodsInSameClass(MethodNode one, MethodNode two) {
         return one.getName().equals(two.getName()) && one.getDeclaringClass() == two.getDeclaringClass();
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/22635dac/src/test/groovy/bugs/Groovy7721Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7721Bug.groovy b/src/test/groovy/bugs/Groovy7721Bug.groovy
deleted file mode 100644
index f316a2a..0000000
--- a/src/test/groovy/bugs/Groovy7721Bug.groovy
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- *  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
-
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
-
-class Groovy7721Bug extends GroovyTestCase {
-    void testCovariantArrayAtOverriding() {
-        def config = new CompilerConfiguration()
-        config.with {
-            targetDirectory = createTempDir()
-            jointCompilationOptions = [stubDir: createTempDir()]
-        }
-
-        File parentDir = createTempDir()
-        try {
-            def a = new File(parentDir, 'A.java')
-            a.write '''
-                    package pack;
-                    interface A {
-                        Object[] bar();
-                    }
-
-                '''
-            def b = new File(parentDir, 'B.java')
-            b.write '''
-                    package pack;
-                    interface B extends A {
-                        @Override
-                        String[] bar();
-                    }
-                '''
-
-            def c = new File(parentDir, 'C.groovy')
-            c.write '''
-            import groovy.transform.CompileStatic
-
-            @CompileStatic
-            class C {
-                static def bar(pack.B b) {
-                    b.bar()
-                }
-            }
-            '''
-            def loader = new GroovyClassLoader(this.class.classLoader)
-            def cu = new JavaAwareCompilationUnit(config, loader)
-            cu.addSources([a, b, c] as File[])
-            cu.compile()
-        } finally {
-            parentDir.deleteDir()
-            config.targetDirectory?.deleteDir()
-            config.jointCompilationOptions.stubDir?.deleteDir()
-        }
-
-    }
-
-    private static File createTempDir() {
-        File.createTempDir("groovyTest${System.currentTimeMillis()}", "")
-    }
-
-}


[2/2] groovy git commit: GROOVY-7721: Static type checking fails when compiling against a Java8 interface with inherited methods

Posted by su...@apache.org.
GROOVY-7721: Static type checking fails when compiling against a Java8 interface with inherited methods

(cherry picked from commit 8ad6e77)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: ddebbeca2a3441895046bc4dfe4a1ea128515dcc
Parents: 22635da
Author: alexey.afanasiev <al...@jetbrains.com>
Authored: Wed Sep 13 18:14:58 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Wed Sep 13 22:48:00 2017 +0800

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingSupport.java          | 11 ++-
 src/test/groovy/bugs/Groovy7721Bug.groovy       | 80 ++++++++++++++++++++
 2 files changed, 89 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ddebbeca/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 98fb157..eb208fe 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1149,13 +1149,20 @@ public abstract class StaticTypeCheckingSupport {
     private static void removeMethodWithSuperReturnType(List<MethodNode> toBeRemoved, MethodNode one, MethodNode two) {
         ClassNode oneRT = one.getReturnType();
         ClassNode twoRT = two.getReturnType();
-        if (oneRT.isDerivedFrom(twoRT) || oneRT.implementsInterface(twoRT)) {
+        if (isCovariant(oneRT, twoRT)) {
             toBeRemoved.add(two);
-        } else if (twoRT.isDerivedFrom(oneRT) || twoRT.implementsInterface(oneRT)) {
+        } else if (isCovariant(twoRT, oneRT)) {
             toBeRemoved.add(one);
         }
     }
 
+    private static boolean isCovariant(ClassNode left, ClassNode right) {
+        if (left.isArray() && right.isArray()) {
+            return isCovariant(left.getComponentType(), right.getComponentType());
+        }
+        return left.isDerivedFrom(right) || left.implementsInterface(right);
+    }
+
     private static boolean areOverloadMethodsInSameClass(MethodNode one, MethodNode two) {
         return one.getName().equals(two.getName()) && one.getDeclaringClass() == two.getDeclaringClass();
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/ddebbeca/src/test/groovy/bugs/Groovy7721Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7721Bug.groovy b/src/test/groovy/bugs/Groovy7721Bug.groovy
new file mode 100644
index 0000000..f316a2a
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7721Bug.groovy
@@ -0,0 +1,80 @@
+/*
+ *  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
+
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
+
+class Groovy7721Bug extends GroovyTestCase {
+    void testCovariantArrayAtOverriding() {
+        def config = new CompilerConfiguration()
+        config.with {
+            targetDirectory = createTempDir()
+            jointCompilationOptions = [stubDir: createTempDir()]
+        }
+
+        File parentDir = createTempDir()
+        try {
+            def a = new File(parentDir, 'A.java')
+            a.write '''
+                    package pack;
+                    interface A {
+                        Object[] bar();
+                    }
+
+                '''
+            def b = new File(parentDir, 'B.java')
+            b.write '''
+                    package pack;
+                    interface B extends A {
+                        @Override
+                        String[] bar();
+                    }
+                '''
+
+            def c = new File(parentDir, 'C.groovy')
+            c.write '''
+            import groovy.transform.CompileStatic
+
+            @CompileStatic
+            class C {
+                static def bar(pack.B b) {
+                    b.bar()
+                }
+            }
+            '''
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources([a, b, c] as File[])
+            cu.compile()
+        } finally {
+            parentDir.deleteDir()
+            config.targetDirectory?.deleteDir()
+            config.jointCompilationOptions.stubDir?.deleteDir()
+        }
+
+    }
+
+    private static File createTempDir() {
+        File.createTempDir("groovyTest${System.currentTimeMillis()}", "")
+    }
+
+}