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 20:05:38 UTC

[groovy] branch GROOVY-8930 updated (372ab65 -> 237c956)

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a change to branch GROOVY-8930
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 372ab65  GROOVY-8579, GROOVY-8930: check static interface method for direct calls
     new 237c956  GROOVY-8579, GROOVY-8930: check static interface method for direct calls

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (372ab65)
            \
             N -- N -- N   refs/heads/GROOVY-8930 (237c956)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


[groovy] 01/01: GROOVY-8579, GROOVY-8930: check static interface method for direct calls

Posted by em...@apache.org.
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 237c956fd624e5310f4eb80802026416473dc8c1
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   | 13 ++++++---
 .../{Groovy8579Bug.groovy => Groovy8579.groovy}    | 32 ++++++++++++++++------
 2 files changed, 33 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..44140c0 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,14 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
 
     protected void storeTargetMethod(final Expression call, final MethodNode directMethodCallCandidate) {
         call.putNodeMetaData(DIRECT_METHOD_CALL_TARGET, directMethodCallCandidate);
+
+        if (directMethodCallCandidate != null
+                && 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
         '''
     }
 }