Add reproduction for not using applied lens in staticizer
Bug: 181493713
Change-Id: I3ec1b2a78064232a88d7c6b559ee19877aaf0b91
diff --git a/src/test/java/com/android/tools/r8/classmerging/horizontal/MergedVirtualMethodStaticizerTest.java b/src/test/java/com/android/tools/r8/classmerging/horizontal/MergedVirtualMethodStaticizerTest.java
new file mode 100644
index 0000000..290ccbb
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/classmerging/horizontal/MergedVirtualMethodStaticizerTest.java
@@ -0,0 +1,77 @@
+// Copyright (c) 2020, 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.classmerging.horizontal;
+
+import com.android.tools.r8.NeverClassInline;
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.TestParameters;
+import org.junit.Test;
+
+public class MergedVirtualMethodStaticizerTest extends HorizontalClassMergingTestBase {
+ public MergedVirtualMethodStaticizerTest(
+ TestParameters parameters, boolean enableHorizontalClassMerging) {
+ super(parameters, enableHorizontalClassMerging);
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(Program.class)
+ .addKeepClassAndMembersRules(Program.Main.class)
+ .addOptionsModification(
+ options ->
+ options.horizontalClassMergerOptions().enableIf(enableHorizontalClassMerging))
+ .enableInliningAnnotations()
+ .enableNeverClassInliningAnnotations()
+ .setMinApi(parameters.getApiLevel())
+ .addHorizontallyMergedClassesInspectorIf(
+ enableHorizontalClassMerging,
+ inspector -> inspector.assertMergedInto(Program.B.class, Program.A.class))
+ .run(parameters.getRuntime(), Program.Main.class)
+ .applyIf(
+ parameters.isDexRuntime() && enableHorizontalClassMerging,
+ // TODO(b/181493713): Should not fail.
+ result -> result.assertFailureWithErrorThatThrows(IncompatibleClassChangeError.class),
+ result -> result.assertSuccessWithOutputLines("A::foo", "Staticized::foo", "B::foo"));
+ }
+
+ public static class Program {
+
+ @NeverClassInline
+ public static class Staticized {
+ public static final Staticized staticized = new Staticized();
+
+ @NeverInline
+ public void foo() {
+ System.out.println("Staticized::foo");
+ }
+ }
+
+ @NeverClassInline
+ public static class A {
+
+ public void foo() {
+ System.out.println("A::foo");
+ Staticized.staticized.foo();
+ }
+ }
+
+ @NeverClassInline
+ public static class B {
+
+ public void foo() {
+ System.out.println("B::foo");
+ }
+ }
+
+ public static class Main {
+
+ public static void main(String[] args) {
+ new A().foo();
+ new B().foo();
+ }
+ }
+ }
+}