You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2017/08/28 04:19:21 UTC

groovy git commit: GROOVY-8303: VerifyError for nested class this call to static method (closes #593)

Repository: groovy
Updated Branches:
  refs/heads/master 8f0fdf0f0 -> b30c3d878


GROOVY-8303: VerifyError for nested class this call to static method (closes #593)


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

Branch: refs/heads/master
Commit: b30c3d8780154fb753d5b227c6ff158f585ab5c0
Parents: 8f0fdf0
Author: John Wagenleitner <jw...@apache.org>
Authored: Sun Aug 27 14:23:29 2017 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sun Aug 27 21:10:46 2017 -0700

----------------------------------------------------------------------
 .../groovy/ast/tools/ClassNodeUtils.java        | 10 ++++++-
 .../groovy/bugs/ConstructorThisCallBug.groovy   | 28 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b30c3d87/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java b/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
index 3c6377a..077e6cb 100644
--- a/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
@@ -30,6 +30,7 @@ import org.codehaus.groovy.ast.expr.MapExpression;
 import org.codehaus.groovy.ast.expr.SpreadExpression;
 import org.codehaus.groovy.ast.expr.TupleExpression;
 
+import java.lang.reflect.Modifier;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -195,7 +196,14 @@ public class ClassNodeUtils {
         return null;
     }
 
+    /**
+     * Detect whether a given ClassNode is a inner class (non-static).
+     *
+     * @param currentClass the ClassNode of interest
+     * @return true if the given node is a (non-static) inner class, else false
+     */
     public static boolean isInnerClass(ClassNode currentClass) {
-        return currentClass.getOuterClass() != null && !currentClass.isStaticClass();
+        return currentClass.redirect().getOuterClass() != null
+                && !Modifier.isStatic(currentClass.getModifiers());
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b30c3d87/src/test/groovy/bugs/ConstructorThisCallBug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/ConstructorThisCallBug.groovy b/src/test/groovy/bugs/ConstructorThisCallBug.groovy
index d9873ec..e6faf9e 100644
--- a/src/test/groovy/bugs/ConstructorThisCallBug.groovy
+++ b/src/test/groovy/bugs/ConstructorThisCallBug.groovy
@@ -31,6 +31,19 @@ class ConstructorThisCallBug extends GroovyTestCase {
         assert msg.contains("Can't access instance method 'getData' before the class is constructed")
     }
 
+    void testNestedClassThisCallingInstanceMethod() {
+        def msg = shouldFail '''
+            class Base {
+                static class Nested {
+                    String getData() { return "ABCD" }
+                    Nested() { this(getData()) }
+                    Nested(String arg) {}
+                }
+            }
+        '''
+        assert msg.contains("Can't access instance method 'getData' before the class is constructed")
+    }
+
     void testThisCallingStaticMethod() {
         assertScript '''
             class Base {
@@ -44,6 +57,21 @@ class ConstructorThisCallBug extends GroovyTestCase {
         '''
     }
 
+    void testNestedThisCallingStaticMethod() {
+        assertScript '''
+            class Base {
+                static class Nested {
+                    private String b
+                    static String getData() { return "ABCD" }
+                    Nested() { this(getData()) }
+                    Nested(String b) { this.b = b }
+                    String toString() { b }
+                }
+            }
+            assert new Base.Nested().toString() == 'ABCD'
+        '''
+    }
+
     void testInnerClassSuperCallingInstanceMethod() {
         assertScript '''
             class Parent {