Add regression test for stripping argument of callsite
Bug: b/231662249
Change-Id: I3fab58ecdcdf6148b7f15ee00a8544e74cbea2cc
diff --git a/src/test/java/com/android/tools/r8/cf/MethodHandleDifferentNameArgumentPropagationTest.java b/src/test/java/com/android/tools/r8/cf/MethodHandleDifferentNameArgumentPropagationTest.java
new file mode 100644
index 0000000..ecacd6d
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/cf/MethodHandleDifferentNameArgumentPropagationTest.java
@@ -0,0 +1,75 @@
+// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.cf;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import java.util.function.Consumer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+/* This is a regression for b/231662249 */
+@RunWith(Parameterized.class)
+public class MethodHandleDifferentNameArgumentPropagationTest extends TestBase {
+
+ private static final String[] EXPECTED =
+ new String[] {"ImplementationInstanceMethod::forEachWithOtherName"};
+
+ @Parameter() public TestParameters parameters;
+
+ @Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withCfRuntimes().build();
+ }
+
+ @Test
+ public void testJvm() throws Exception {
+ testForJvm()
+ .addInnerClasses(MethodHandleDifferentNameArgumentPropagationTest.class)
+ .run(parameters.getRuntime(), Main.class)
+ .assertSuccessWithOutputLines(EXPECTED);
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(MethodHandleDifferentNameArgumentPropagationTest.class)
+ .addKeepMainRule(Main.class)
+ .addOptionsModification(
+ options -> options.apiModelingOptions().disableApiCallerIdentification())
+ .run(parameters.getRuntime(), Main.class)
+ // TODO(b/231662249): Should not throw an error.
+ .assertFailureWithErrorThatThrows(BootstrapMethodError.class);
+ }
+
+ public interface Foreachable {
+ void forEach(Consumer<String> consumer);
+ }
+
+ public static class ImplementationInstanceMethod {
+
+ public void forEachWithOtherName(Consumer<String> consumer) {
+ consumer.accept("ImplementationInstanceMethod::forEachWithOtherName");
+ }
+ }
+
+ public static class ImplementationInstanceMethodSub extends ImplementationInstanceMethod {}
+
+ public static class Main {
+
+ public static void test(Foreachable foreachable) {
+ foreachable.forEach(System.out::println);
+ }
+
+ public static void main(String[] args) {
+ ImplementationInstanceMethodSub impl = new ImplementationInstanceMethodSub();
+ test(impl::forEachWithOtherName);
+ }
+ }
+}