blob: b27e96a308ff4d427d2f1fbd0b89021f4f52a1c9 [file] [log] [blame]
// 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.regress;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.utils.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class UndefinedLambdaInterfaceRegress232379893 extends TestBase {
static final String EXPECTED = StringUtils.lines("Hello, world");
private final TestParameters parameters;
@Parameterized.Parameters(name = "{0}")
public static TestParametersCollection data() {
return getTestParameters().withAllRuntimes().withAllApiLevels().build();
}
public UndefinedLambdaInterfaceRegress232379893(TestParameters parameters) {
this.parameters = parameters;
}
@Test
public void test() throws Exception {
testForR8(parameters.getBackend())
.addProgramClasses(TestClass.class)
.addProgramClassesAndInnerClasses(UserOfUndefinedInterface.class)
.addKeepMainRule(TestClass.class)
.addDontWarn(UndefinedInterface.class)
.addDontShrink()
.setMinApi(parameters.getApiLevel())
.run(parameters.getRuntime(), TestClass.class)
.assertSuccessWithOutput(EXPECTED);
}
interface UndefinedInterface {
void foo();
}
static class UserOfUndefinedInterface {
public static void bar(UndefinedInterface i) {
throw new RuntimeException("unused method");
}
}
static class TestClass {
public static void main(String[] args) {
if (System.nanoTime() < 0) {
UserOfUndefinedInterface.bar(() -> System.out.println("unused lambda"));
} else {
System.out.println("Hello, world");
}
}
}
}