groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] 02/02: GROOVY-8762: make WriterController#isInClosure() more selective
Date Mon, 25 Nov 2019 23:26:18 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 3cbc7e3170330d250dc5a2036f910dbf15664199
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Mon Nov 25 17:26:10 2019 -0600

    GROOVY-8762: make WriterController#isInClosure() more selective
    
    - any inner class that extended Closure got closure literal treatment
---
 .../groovy/classgen/asm/WriterController.java      |  7 +++----
 src/test/groovy/bugs/Groovy8762.groovy             | 22 +++++++---------------
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
index a3cb6df..7b88390 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -284,13 +284,12 @@ public class WriterController {
 
     public boolean isInClosure() {
         return classNode.getOuterClass() != null
-                && classNode.getSuperClass() == ClassHelper.CLOSURE_TYPE;
+                && classNode.getSuperClass().equals(ClassHelper.CLOSURE_TYPE)
+                && classNode.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type);
     }
 
     public boolean isInClosureConstructor() {
-        return constructorNode != null
-                && classNode.getOuterClass() != null
-                && classNode.getSuperClass() == ClassHelper.CLOSURE_TYPE;
+        return isConstructor() && isInClosure();
     }
 
     public boolean isStaticMethod() {
diff --git a/src/test/groovy/bugs/Groovy8762.groovy b/src/test/groovy/bugs/Groovy8762.groovy
index cb8c390..9fd5383 100644
--- a/src/test/groovy/bugs/Groovy8762.groovy
+++ b/src/test/groovy/bugs/Groovy8762.groovy
@@ -18,7 +18,6 @@
  */
 package groovy.bugs
 
-import groovy.test.NotYetImplemented
 import groovy.transform.CompileStatic
 import org.junit.Test
 
@@ -27,7 +26,7 @@ import static groovy.test.GroovyAssert.assertScript
 @CompileStatic
 final class Groovy8762 {
 
-    @Test @NotYetImplemented
+    @Test
     void testExplicitThisObjectExpressionInInnerClassConstructor() {
         assertScript '''
             class Outer {
@@ -40,23 +39,15 @@ final class Groovy8762 {
                         this.y = i // NPE at groovy.bugs.Outer$Inner.<init>
                     }
 
-                    int getMaximumNumberOfParameters() {
-                        throw new UnsupportedOperationException()
-                    }
-
-                    Class<?>[] getParameterTypes() {
-                        throw new UnsupportedOperationException()
+                    def doCall(... args) {
+                        return 42
                     }
 
-                    Object call(Object... args) {
-                        throw new UnsupportedOperationException()
-                    }
-
-                    Object call(Object arguments) {
+                    int getMaximumNumberOfParameters() {
                         throw new UnsupportedOperationException()
                     }
 
-                    Object call() {
+                    Class<?>[] getParameterTypes() {
                         throw new UnsupportedOperationException()
                     }
                 }
@@ -66,7 +57,8 @@ final class Groovy8762 {
                 }
             }
 
-            assert new Outer().makeCallable()
+            def callback = new Outer().makeCallable()
+            assert callback() == 42
         '''
     }
 }


Mime
View raw message