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 2019/04/08 12:59:12 UTC

[groovy] 20/20: GROOVY-9008: add bytecode test

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

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ffae2ba9c5ec44384d6456a28a2b54179c02b4ba
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Apr 8 18:36:26 2019 +1000

    GROOVY-9008: add bytecode test
---
 .../classgen/asm/sc/StaticCompilationTest.groovy   | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompilationTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompilationTest.groovy
index 318f692..9a39fbc 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompilationTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/StaticCompilationTest.groovy
@@ -19,6 +19,7 @@
 package org.codehaus.groovy.classgen.asm.sc
 
 import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
+import org.codehaus.groovy.runtime.MethodClosure
 
 import static org.codehaus.groovy.control.CompilerConfiguration.DEFAULT as config
 
@@ -691,4 +692,29 @@ assert o.blah() == 'outer'
                 'ISTORE'
         ])
     }
+
+    void testInstanceMethodReference() {
+        // dynamic case should be a method closure
+        assert String::toUpperCase instanceof MethodClosure
+
+        // static case should be compiled into functional interface
+        String code = '''
+        import groovy.transform.CompileStatic
+        import java.util.stream.Collectors
+
+        @CompileStatic
+        void m() {
+            assert ['foo'].stream().map(String::toUpperCase).collect(Collectors.toList()) == ['FOO']
+        }
+        m()
+        '''
+        assert compile([method:'m'],code).hasSequence([
+                'INVOKEDYNAMIC apply()Ljava/util/function/Function;',
+                /* handle kind 0x6 : INVOKESTATIC */
+                'java/lang/invoke/LambdaMetafactory.metafactory',
+                /* handle kind 0x5 : INVOKEVIRTUAL */
+                'java/lang/String.toUpperCase()Ljava/lang/String;'
+        ])
+        assertScript(code)
+    }
 }