From 984dc4f89f8f1a6b96a2bea2638ecc7afd4493c8 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Tue, 14 Feb 2023 11:27:50 -0600 Subject: [PATCH] GROOVY-10933 --- .../tests/xform/StaticCompilationTests.java | 24 +++++++++++++++++++ ...cTypesMethodReferenceExpressionWriter.java | 4 ++++ ...cTypesMethodReferenceExpressionWriter.java | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java index d85e35f46b..0aa1b7c867 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java @@ -8100,4 +8100,28 @@ public void testCompileStatic10904() { runConformTest(sources, "1"); } + + @Test + public void testCompileStatic10933() { + assumeTrue(isParrotParser()); + + //@formatter:off + String[] sources = { + "Main.groovy", + "@groovy.transform.CompileStatic\n" + + "class Main {\n" + + " List strings = []\n" + + " void run() {\n" + + " Optional.of('works').ifPresent(strings::add)\n" + + " }\n" + + " static main(args) {\n" + + " def obj = this.newInstance()\n" + + " obj.run(); print obj.strings\n" + + " }\n" + + "}\n", + }; + //@formatter:on + + runConformTest(sources, "[works]"); + } } diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java index a945b456d5..fdd17bb1f7 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java @@ -147,6 +147,10 @@ public void writeMethodReferenceExpression(final MethodReferenceExpression metho parametersWithExactType, false ); + // GRECLIPSE add -- GROOVY-10933 + if (abstractMethod.isVoidMethod()) bootstrapArgs[2] = groovyjarjarasm.asm.Type.getType( + BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, parametersWithExactType)); + // GRECLIPSE end controller.getMethodVisitor().visitInvokeDynamicInsn(methodName, methodDesc, bootstrapMethod, bootstrapArgs); if (isClassExpression) { diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java index 69c4edc1e2..2630fd4827 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java @@ -174,6 +174,10 @@ public void writeMethodReferenceExpression(final MethodReferenceExpression metho parametersWithExactType, false ); + // GRECLIPSE add -- GROOVY-10933 + if (abstractMethod.isVoidMethod()) bootstrapArgs[2] = groovyjarjarasm.asm.Type.getType( + BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, parametersWithExactType)); + // GRECLIPSE end controller.getMethodVisitor().visitInvokeDynamicInsn(methodName, methodDesc, bootstrapMethod, bootstrapArgs); if (isClassExpression) {