Add a class merging test for use of -keepparameternames

Note that, if a method is kept by a keep rule, we already pin all of the types in the given method signature (including the return type).

Change-Id: I4c7db5aae69e7266ed183281b8424b868c224075
diff --git a/src/test/examples/classmerging/PinnedParameterTypesTest.java b/src/test/examples/classmerging/PinnedParameterTypesTest.java
new file mode 100644
index 0000000..bdfe3b7
--- /dev/null
+++ b/src/test/examples/classmerging/PinnedParameterTypesTest.java
@@ -0,0 +1,47 @@
+// Copyright (c) 2018, 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 classmerging;
+
+import java.lang.reflect.Method;
+
+public class PinnedParameterTypesTest {
+
+  public static void main(String[] args) throws Exception {
+    for (Method method : TestClass.class.getMethods()) {
+      if (method.getName().equals("method")) {
+        Class<?> parameterType = method.getParameterTypes()[0];
+
+        // Should print classmerging.PinnedParameterTypesTest$Interface when -keepparameternames is
+        // used.
+        System.out.println(parameterType.getName());
+
+        method.invoke(null, new InterfaceImpl());
+        break;
+      }
+    }
+  }
+
+  public interface Interface {
+
+    void foo();
+  }
+
+  public static class InterfaceImpl implements Interface {
+
+    @Override
+    public void foo() {
+      System.out.println("In InterfaceImpl.foo()");
+    }
+  }
+
+  public static class TestClass {
+
+    // This method has been kept explicitly by a keep rule. Therefore, since -keepparameternames is
+    // used, Interface must not be merged into InterfaceImpl.
+    public static void method(Interface obj) {
+      obj.foo();
+    }
+  }
+}
diff --git a/src/test/examples/classmerging/keep-rules.txt b/src/test/examples/classmerging/keep-rules.txt
index fa48747..516e39d 100644
--- a/src/test/examples/classmerging/keep-rules.txt
+++ b/src/test/examples/classmerging/keep-rules.txt
@@ -19,6 +19,12 @@
 -keep public class classmerging.RewritePinnedMethodTest {
   public static void main(...);
 }
+-keep public class classmerging.PinnedParameterTypesTest {
+  public static void main(...);
+}
+-keep public class classmerging.PinnedParameterTypesTest$TestClass {
+  public static void method(...);
+}
 -keep public class classmerging.SimpleInterfaceAccessTest {
   public static void main(...);
 }
diff --git a/src/test/java/com/android/tools/r8/classmerging/ClassMergingTest.java b/src/test/java/com/android/tools/r8/classmerging/ClassMergingTest.java
index 4da4821..9ca9290 100644
--- a/src/test/java/com/android/tools/r8/classmerging/ClassMergingTest.java
+++ b/src/test/java/com/android/tools/r8/classmerging/ClassMergingTest.java
@@ -207,6 +207,29 @@
   }
 
   @Test
+  public void testPinnedParameterTypes() throws Exception {
+    String main = "classmerging.PinnedParameterTypesTest";
+    Path[] programFiles =
+        new Path[] {
+          CF_DIR.resolve("PinnedParameterTypesTest.class"),
+          CF_DIR.resolve("PinnedParameterTypesTest$Interface.class"),
+          CF_DIR.resolve("PinnedParameterTypesTest$InterfaceImpl.class"),
+          CF_DIR.resolve("PinnedParameterTypesTest$TestClass.class")
+        };
+    Set<String> preservedClassNames =
+        ImmutableSet.of(
+            "classmerging.PinnedParameterTypesTest",
+            "classmerging.PinnedParameterTypesTest$Interface",
+            "classmerging.PinnedParameterTypesTest$InterfaceImpl",
+            "classmerging.PinnedParameterTypesTest$TestClass");
+    runTest(
+        main,
+        programFiles,
+        preservedClassNames::contains,
+        getProguardConfig(EXAMPLE_KEEP, "-keepparameternames"));
+  }
+
+  @Test
   public void testSuperCallWasDetected() throws Exception {
     String main = "classmerging.SuperCallRewritingTest";
     Path[] programFiles =