You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/05/18 08:18:05 UTC

groovy git commit: GROOVY-8579: No bytecode level check is done before producing JDK8+ bytecode (closes #709)

Repository: groovy
Updated Branches:
  refs/heads/master 31dbe4e19 -> 7d950582f


GROOVY-8579: No bytecode level check is done before producing JDK8+ bytecode (closes #709)


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

Branch: refs/heads/master
Commit: 7d950582fc44a17fbef65eb9f9acbaacd32495f5
Parents: 31dbe4e
Author: Paul King <pa...@asert.com.au>
Authored: Thu May 17 19:00:18 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri May 18 18:16:08 2018 +1000

----------------------------------------------------------------------
 .../groovy/classgen/AsmClassGenerator.java      | 11 ++++++-
 .../stc/StaticTypeCheckingVisitor.java          |  5 +++
 src/test/groovy/bugs/Groovy8579Bug.groovy       | 34 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/7d950582/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 476337b..c161905 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -171,6 +171,7 @@ public class AsmClassGenerator extends ClassGenerator {
     public static final boolean CREATE_DEBUG_INFO = true;
     public static final boolean CREATE_LINE_NUMBER_INFO = true;
     public static final boolean ASM_DEBUG = false; // add marker in the bytecode to show source-bytecode relationship
+    public static final String MINIMUM_BYTECODE_VERSION = "_MINIMUM_BYTECODE_VERSION";
 
     private ASTNode currentASTNode = null;
     private final Map genericParameterNames;
@@ -215,8 +216,16 @@ public class AsmClassGenerator extends ClassGenerator {
         }
 
         try {
+            int bytecodeVersion = controller.getBytecodeVersion();
+            Object min = classNode.getNodeMetaData(MINIMUM_BYTECODE_VERSION);
+            if (min instanceof Integer) {
+                int minVersion = (int) min;
+                if (bytecodeVersion < minVersion) {
+                    bytecodeVersion = minVersion;
+                }
+            }
             cv.visit(
-                    controller.getBytecodeVersion(),
+                    bytecodeVersion,
                     adjustedClassModifiersForClassWriting(classNode),
                     controller.getInternalClassName(),
                     BytecodeHelper.getGenericsSignature(classNode),

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d950582/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
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 5f9e1cb..00b8974 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -179,6 +179,7 @@ import static org.codehaus.groovy.ast.tools.WideningCategories.isIntCategory;
 import static org.codehaus.groovy.ast.tools.WideningCategories.isLongCategory;
 import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
 import static org.codehaus.groovy.ast.tools.WideningCategories.lowestUpperBound;
+import static org.codehaus.groovy.classgen.AsmClassGenerator.MINIMUM_BYTECODE_VERSION;
 import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
 import static org.codehaus.groovy.syntax.Types.ASSIGN;
 import static org.codehaus.groovy.syntax.Types.ASSIGNMENT_OPERATOR;
@@ -3251,6 +3252,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
 
                             storeType(call, returnType);
                             storeTargetMethod(call, directMethodCallCandidate);
+                            ClassNode declaringClass = directMethodCallCandidate.getDeclaringClass();
+                            if (declaringClass.isInterface() && directMethodCallCandidate.isStatic()) {
+                                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

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d950582/src/test/groovy/bugs/Groovy8579Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8579Bug.groovy b/src/test/groovy/bugs/Groovy8579Bug.groovy
new file mode 100644
index 0000000..1945e47
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8579Bug.groovy
@@ -0,0 +1,34 @@
+/*
+ *  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 Groovy8579Bug extends GroovyTestCase {
+    void testCallToStaticInterfaceMethod() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+
+            @CompileStatic
+            Comparator myMethod() {
+                Map.Entry.comparingByKey()
+            }
+
+            assert myMethod() instanceof Comparator
+        '''
+    }
+}