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/09/22 17:06:35 UTC
groovy git commit: GROOVY-8327: Can't access static instance method
before class is constructed(closes #801)
Repository: groovy
Updated Branches:
refs/heads/master 10c968513 -> 87c631035
GROOVY-8327: Can't access static instance method before class is constructed(closes #801)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/87c63103
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/87c63103
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/87c63103
Branch: refs/heads/master
Commit: 87c6310350de68a56d1721d32671747dc23cf549
Parents: 10c9685
Author: Daniel Sun <su...@apache.org>
Authored: Sun Sep 23 01:06:03 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Sun Sep 23 01:06:03 2018 +0800
----------------------------------------------------------------------
.../groovy/control/StaticImportVisitor.java | 6 +
src/test/groovy/bugs/Groovy8327Bug.groovy | 113 +++++++++++++++++++
2 files changed, 119 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/87c63103/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 93f5929..f271de0 100644
--- a/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/StaticImportVisitor.java
@@ -329,6 +329,12 @@ public class StaticImportVisitor extends ClassCodeExpressionTransformer {
return smce;
}
}
+
+ if (mce.isImplicitThis() && lookForPossibleStaticMethod && hasPossibleStaticMethod(currentClass, methodName, args, true)) {
+ StaticMethodCallExpression result = new StaticMethodCallExpression(currentClass, methodName, args);
+ result.setSourcePosition(mce);
+ return result;
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/87c63103/src/test/groovy/bugs/Groovy8327Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8327Bug.groovy b/src/test/groovy/bugs/Groovy8327Bug.groovy
new file mode 100644
index 0000000..1dbb279
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8327Bug.groovy
@@ -0,0 +1,113 @@
+/*
+ * 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 Groovy8327Bug extends GroovyTestCase {
+ void testCallStaticMethodInClosureParamOfThisConstructor() {
+ assertScript '''
+ class A {
+ static String g() { 'abc' }
+ A() {
+ this({g()})
+ }
+ A(a) { assert 'abc' == a() }
+ }
+
+ assert new A()
+ '''
+ }
+
+ void testCallStaticMethodInThisConstructor() {
+ assertScript '''
+ class A {
+ static String g() { 'abc' }
+ A() {
+ this(g())
+ }
+ A(a) { assert 'abc' == a }
+ }
+
+ assert new A()
+ '''
+ }
+
+ void testCallStaticMethodInClosureParamOfSuperConstructor() {
+ assertScript '''
+ class B {
+ B(b) { assert 'abc' == b() }
+ }
+ class A extends B {
+ static String g() { 'abc' }
+ A() {
+ super({g()})
+ }
+ }
+
+ assert new A()
+ '''
+ }
+
+ void testCallStaticMethodInSuperConstructor() {
+ assertScript '''
+ class B {
+ B(b) { assert 'abc' == b }
+ }
+ class A extends B {
+ static String g() { 'abc' }
+ A() {
+ super(g())
+ }
+ }
+
+ assert new A()
+ '''
+ }
+
+ void testCallSuperStaticMethodInClosureParamOfSuperConstructor() {
+ assertScript '''
+ class B {
+ B(b) { assert 'abc' == b() }
+ static String g() { 'abc' }
+ }
+ class A extends B {
+ A() {
+ super({g()})
+ }
+ }
+
+ assert new A()
+ '''
+ }
+
+ void testCallSuperStaticMethodInSuperConstructor() {
+ assertScript '''
+ class B {
+ B(b) { assert 'abc' == b }
+ static String g() { 'abc' }
+ }
+ class A extends B {
+ A() {
+ super(g())
+ }
+ }
+
+ assert new A()
+ '''
+ }
+}