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 2018/10/07 12:22:12 UTC

groovy git commit: GROOVY-8819: java.lang.VerifyError when calling this() with static final field from a super class(closes #807)

Repository: groovy
Updated Branches:
  refs/heads/master 5ff63b1cd -> f4e57455d


GROOVY-8819: java.lang.VerifyError when calling this() with static final field from a super class(closes #807)


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

Branch: refs/heads/master
Commit: f4e57455de793123d0007d7183806731442efe82
Parents: 5ff63b1
Author: Daniel Sun <su...@apache.org>
Authored: Sun Oct 7 20:22:07 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Sun Oct 7 20:22:07 2018 +0800

----------------------------------------------------------------------
 .../groovy/control/StaticImportVisitor.java     | 11 ++++
 src/test/groovy/bugs/Groovy8819Bug.groovy       | 56 ++++++++++++++++++++
 2 files changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f4e57455/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java b/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
index f271de0..9adda6e 100644
--- a/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
@@ -208,6 +208,17 @@ public class StaticImportVisitor extends ClassCodeExpressionTransformer {
                 }
                 return result;
             }
+        } else if (v instanceof FieldNode) {
+            if (inSpecialConstructorCall) { // GROOVY-8819
+                FieldNode fn = (FieldNode) v;
+                ClassNode declaringClass = fn.getDeclaringClass();
+                if (fn.isStatic() && currentClass.isDerivedFrom(declaringClass)) {
+                    Expression result = new PropertyExpression(new ClassExpression(declaringClass), v.getName());
+                    result.setSourcePosition(ve);
+
+                    return result;
+                }
+            }
         }
         return ve;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/f4e57455/src/test/groovy/bugs/Groovy8819Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8819Bug.groovy b/src/test/groovy/bugs/Groovy8819Bug.groovy
new file mode 100644
index 0000000..1203eb7
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8819Bug.groovy
@@ -0,0 +1,56 @@
+/*
+ *  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
+
+class Groovy8819Bug extends GroovyTestCase {
+    void testAccessStaticFieldInThisConstructor() {
+        assertScript '''
+            class Parent { 
+                static final String DEFAULT = 'default' 
+            }
+            class Child extends Parent {
+                String value
+                Child() { this(DEFAULT) }
+                Child(String value) { this.value = value }
+            }
+            
+            assert 'default' == new Child().value
+        '''
+    }
+
+    void testAccessStaticFieldInThisConstructorCS() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+
+            @CompileStatic
+            class Parent { 
+                static final String DEFAULT = 'default' 
+            }
+            
+            @CompileStatic
+            class Child extends Parent {
+                String value
+                Child() { this(DEFAULT) }
+                Child(String value) { this.value = value }
+            }
+            
+            assert 'default' == new Child().value
+        '''
+    }
+}