blob: dad75a47aa8a952a5477f6a1564833d7aca3baf0 [file] [log] [blame]
// 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.classmerging.horizontal.interfaces;
import static org.junit.Assert.assertFalse;
import com.android.tools.r8.NoUnusedInterfaceRemoval;
import com.android.tools.r8.NoVerticalClassMerging;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class DisjointFunctionalInterfacesWithIntersectionMergingTest extends TestBase {
private final TestParameters parameters;
@Parameterized.Parameters(name = "{0}")
public static TestParametersCollection data() {
return getTestParameters().withAllRuntimesAndApiLevels().build();
}
public DisjointFunctionalInterfacesWithIntersectionMergingTest(TestParameters parameters) {
this.parameters = parameters;
}
@Test
public void test() throws Exception {
testForR8(parameters.getBackend())
.addInnerClasses(getClass())
.addKeepMainRule(Main.class)
.addHorizontallyMergedClassesInspector(
inspector -> inspector.assertIsCompleteMergeGroup(I.class, J.class))
.addOptionsModification(
options -> {
assertFalse(options.horizontalClassMergerOptions().isInterfaceMergingEnabled());
options.horizontalClassMergerOptions().enableInterfaceMerging();
})
.enableNoUnusedInterfaceRemovalAnnotations()
.enableNoVerticalClassMergingAnnotations()
.noClassInliningOfSynthetics()
.noHorizontalClassMergingOfSynthetics()
.noInliningOfSynthetics()
.setMinApi(parameters.getApiLevel())
.compile()
.run(parameters.getRuntime(), Main.class)
.assertSuccessWithOutputLines("I & J", "I & J");
}
static class Main {
public static void main(String[] args) {
Object o = (I & J) () -> System.currentTimeMillis() > 0 ? "I & J" : null;
System.out.println(((I) o).f());
System.out.println(((J) o).f());
}
}
@NoUnusedInterfaceRemoval
@NoVerticalClassMerging
interface I {
Object f();
}
@NoUnusedInterfaceRemoval
@NoVerticalClassMerging
interface J {
String f();
}
}