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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Daniel.Sun
Repository: groovy
Updated Branches:
  refs/heads/master a4f779335 -> 695b7afb7


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

This reverts commit 34df6cf461a5ecce66f2c2c0f14489cf96feaf34.


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

Branch: refs/heads/master
Commit: 695b7afb7b2652b0e2043189b8c0b3c97f97c2c4
Parents: a4f7793
Author: sunlan <[hidden email]>
Authored: Wed Sep 13 22:35:50 2017 +0800
Committer: sunlan <[hidden email]>
Committed: Wed Sep 13 22:35:50 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/695b7afb/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/695b7afb/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()}", "")
-    }
-
-}