You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2019/11/15 19:10:00 UTC
[groovy] 01/01: GROOVY-8579,
GROOVY-8930: check static interface method for direct calls
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY-8930
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 372ab65bc8f1705f41e9aa82d101bcdd8b801fbf
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Nov 15 13:09:44 2019 -0600
GROOVY-8579, GROOVY-8930: check static interface method for direct calls
- calling a static interface method requires Java 1.8+ bytecode
---
.../transform/stc/StaticTypeCheckingVisitor.java | 12 +++++---
.../{Groovy8579Bug.groovy => Groovy8579.groovy} | 32 ++++++++++++++++------
2 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 0725829..e91626d 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3492,10 +3492,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
storeType(call, returnType);
storeTargetMethod(call, directMethodCallCandidate);
- ClassNode declaringClass = directMethodCallCandidate.getDeclaringClass();
- if (declaringClass.isInterface() && directMethodCallCandidate.isStatic() && !(directMethodCallCandidate instanceof ExtensionMethodNode)) {
- typeCheckingContext.getEnclosingClassNode().putNodeMetaData(MINIMUM_BYTECODE_VERSION, Opcodes.V1_8);
- }
+
String data = chosenReceiver.getData();
if (data != null) {
// the method which has been chosen is supposed to be a call on delegate or owner
@@ -3768,6 +3765,13 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
protected void storeTargetMethod(final Expression call, final MethodNode directMethodCallCandidate) {
call.putNodeMetaData(DIRECT_METHOD_CALL_TARGET, directMethodCallCandidate);
+
+ if (directMethodCallCandidate.isStatic()
+ && directMethodCallCandidate.getDeclaringClass().isInterface()
+ && !(directMethodCallCandidate instanceof ExtensionMethodNode)) {
+ typeCheckingContext.getEnclosingClassNode().putNodeMetaData(MINIMUM_BYTECODE_VERSION, Opcodes.V1_8);
+ }
+
checkOrMarkPrivateAccess(call, directMethodCallCandidate);
checkSuperCallFromClosure(call, directMethodCallCandidate);
extension.onMethodSelection(call, directMethodCallCandidate);
diff --git a/subprojects/tests-vm8/src/test/groovy/groovy/bugs/vm8/Groovy8579Bug.groovy b/subprojects/tests-vm8/src/test/groovy/groovy/bugs/vm8/Groovy8579.groovy
similarity index 60%
rename from subprojects/tests-vm8/src/test/groovy/groovy/bugs/vm8/Groovy8579Bug.groovy
rename to subprojects/tests-vm8/src/test/groovy/groovy/bugs/vm8/Groovy8579.groovy
index 153f33f..8105cea 100644
--- a/subprojects/tests-vm8/src/test/groovy/groovy/bugs/vm8/Groovy8579Bug.groovy
+++ b/subprojects/tests-vm8/src/test/groovy/groovy/bugs/vm8/Groovy8579.groovy
@@ -18,19 +18,35 @@
*/
package groovy.bugs.vm8
-import groovy.test.GroovyTestCase
+import org.junit.Test
-class Groovy8579Bug extends GroovyTestCase {
- void testCallToStaticInterfaceMethod() {
- assertScript '''
- import groovy.transform.CompileStatic
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy8579 {
- @CompileStatic
- Comparator myMethod() {
+ @Test
+ void testCallToStaticInterfaceMethod1() {
+ assertScript '''
+ @groovy.transform.CompileStatic
+ Comparator test() {
Map.Entry.comparingByKey()
}
- assert myMethod() instanceof Comparator
+ assert test() instanceof Comparator
+ '''
+ }
+
+ @Test
+ void testCallToStaticInterfaceMethod2() {
+ assertScript '''
+ import static java.util.Map.Entry.comparingByKey
+
+ @groovy.transform.CompileStatic
+ Comparator test() {
+ comparingByKey()
+ }
+
+ assert test() instanceof Comparator
'''
}
}