Add a reproduction of issue 197625454

Bug: 197625454
Change-Id: Ie4a80be8afa586006b2a2842d135e712f9b0642f
diff --git a/src/test/java/com/android/tools/r8/desugar/lambdas/OverlappingLambdaMethodInSubclassWithSameNameTest.java b/src/test/java/com/android/tools/r8/desugar/lambdas/OverlappingLambdaMethodInSubclassWithSameNameTest.java
new file mode 100644
index 0000000..3dd750e
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/desugar/lambdas/OverlappingLambdaMethodInSubclassWithSameNameTest.java
@@ -0,0 +1,76 @@
+// Copyright (c) 2021, 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.desugar.lambdas;
+
+import static org.junit.Assume.assumeTrue;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.desugar.lambdas.b197625454.OverlappingLambdaMethodInSubclassWithSameNameTestA;
+import com.android.tools.r8.desugar.lambdas.b197625454.OverlappingLambdaMethodInSubclassWithSameNameTestB;
+import com.android.tools.r8.utils.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+
+// See b/197625454 for details.
+@RunWith(Parameterized.class)
+public class OverlappingLambdaMethodInSubclassWithSameNameTest extends TestBase {
+
+  static final String EXPECTED =
+      StringUtils.lines("Superclass lambda: Hello!", "Superclass lambda: Hello!");
+
+  static final String UNEXPECTED_D8_B197625454 =
+      StringUtils.lines("Subclass lambda: Hello!", "Superclass lambda: Hello!");
+
+  private static final Class<?> MAIN_CLASS =
+      com.android.tools.r8.desugar.lambdas.b197625454.subpackage
+          .OverlappingLambdaMethodInSubclassWithSameNameTestA.class;
+
+  @Parameter() public TestParameters parameters;
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimes().withAllApiLevelsAlsoForCf().build();
+  }
+
+  @Test
+  public void testJvm() throws Exception {
+    assumeTrue(parameters.isCfRuntime());
+    testForRuntime(parameters)
+        .addProgramClasses(
+            MAIN_CLASS,
+            OverlappingLambdaMethodInSubclassWithSameNameTestA.class,
+            OverlappingLambdaMethodInSubclassWithSameNameTestB.class)
+        .run(parameters.getRuntime(), MAIN_CLASS)
+        .assertSuccessWithOutput(EXPECTED);
+  }
+
+  @Test
+  public void testD8() throws Exception {
+    testForD8(parameters.getBackend())
+        .addProgramClasses(
+            MAIN_CLASS,
+            OverlappingLambdaMethodInSubclassWithSameNameTestA.class,
+            OverlappingLambdaMethodInSubclassWithSameNameTestB.class)
+        .setMinApi(parameters.getApiLevel())
+        .run(parameters.getRuntime(), MAIN_CLASS)
+        .assertSuccessWithOutput(UNEXPECTED_D8_B197625454);
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    testForR8(parameters.getBackend())
+        .addProgramClasses(
+            MAIN_CLASS,
+            OverlappingLambdaMethodInSubclassWithSameNameTestA.class,
+            OverlappingLambdaMethodInSubclassWithSameNameTestB.class)
+        .setMinApi(parameters.getApiLevel())
+        .addKeepMainRule(MAIN_CLASS)
+        .run(parameters.getRuntime(), MAIN_CLASS)
+        .assertSuccessWithOutput(EXPECTED);
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/OverlappingLambdaMethodInSubclassWithSameNameTestA.java b/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/OverlappingLambdaMethodInSubclassWithSameNameTestA.java
new file mode 100644
index 0000000..25be7d6
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/OverlappingLambdaMethodInSubclassWithSameNameTestA.java
@@ -0,0 +1,24 @@
+// Copyright (c) 2021, 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.desugar.lambdas.b197625454;
+
+// Same base class name as the class it extends. See b/197625454 for details.
+public class OverlappingLambdaMethodInSubclassWithSameNameTestA
+    extends com.android.tools.r8.desugar.lambdas.b197625454.subpackage
+        .OverlappingLambdaMethodInSubclassWithSameNameTestA {
+
+  @Override
+  public void myMethod() {
+    super.myMethod();
+    if (Math.random() < 0) { // always false
+      Runnable local = () -> System.out.println("Subclass lambda: " + getString());
+    }
+    r.run();
+  }
+
+  @Override
+  public String getString() {
+    return "Hello!";
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/OverlappingLambdaMethodInSubclassWithSameNameTestB.java b/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/OverlappingLambdaMethodInSubclassWithSameNameTestB.java
new file mode 100644
index 0000000..45193ef
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/OverlappingLambdaMethodInSubclassWithSameNameTestB.java
@@ -0,0 +1,24 @@
+// Copyright (c) 2021, 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.desugar.lambdas.b197625454;
+
+import com.android.tools.r8.desugar.lambdas.b197625454.subpackage.OverlappingLambdaMethodInSubclassWithSameNameTestA;
+
+public class OverlappingLambdaMethodInSubclassWithSameNameTestB
+    extends OverlappingLambdaMethodInSubclassWithSameNameTestA {
+
+  @Override
+  public void myMethod() {
+    super.myMethod();
+    if (Math.random() < 0) { // always false
+      Runnable local = () -> System.out.println("Subclass lambda: " + getString());
+    }
+    r.run();
+  }
+
+  @Override
+  public String getString() {
+    return "Hello!";
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/subpackage/OverlappingLambdaMethodInSubclassWithSameNameTestA.java b/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/subpackage/OverlappingLambdaMethodInSubclassWithSameNameTestA.java
new file mode 100644
index 0000000..3f8bdcd
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/desugar/lambdas/b197625454/subpackage/OverlappingLambdaMethodInSubclassWithSameNameTestA.java
@@ -0,0 +1,24 @@
+// Copyright (c) 2021, 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.desugar.lambdas.b197625454.subpackage;
+
+import com.android.tools.r8.desugar.lambdas.b197625454.OverlappingLambdaMethodInSubclassWithSameNameTestB;
+
+public abstract class OverlappingLambdaMethodInSubclassWithSameNameTestA {
+
+  public Runnable r;
+
+  public void myMethod() {
+    r = () -> System.out.println("Superclass lambda: " + getString());
+  }
+
+  public abstract String getString();
+
+  public static void main(String[] args) {
+    new com.android.tools.r8.desugar.lambdas.b197625454
+            .OverlappingLambdaMethodInSubclassWithSameNameTestA()
+        .myMethod();
+    new OverlappingLambdaMethodInSubclassWithSameNameTestB().myMethod();
+  }
+}