blob: f5b82ad6b76391659f78a9465c657d9a0d3e05e7 [file] [log] [blame]
// 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.missingclasses;
import com.android.tools.r8.CompilationFailedException;
import com.android.tools.r8.TestDiagnosticMessages;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.references.MethodReference;
import com.android.tools.r8.references.Reference;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
/**
* If a method reference that refers to a missing class resolves to a definition, then the method
* definition is to be blamed, and not the enclosing method.
*/
public class MissingClassReferencedFromInvokeVirtualToPresentMethodParameterTest
extends MissingClassesTestBase {
private static final MethodReference referencedFrom =
Reference.method(
Reference.classFromClass(Main.class),
"get",
ImmutableList.of(Reference.classFromClass(MissingClass.class)),
null);
public MissingClassReferencedFromInvokeVirtualToPresentMethodParameterTest(
TestParameters parameters) {
super(parameters);
}
@Test(expected = CompilationFailedException.class)
public void testNoRules() throws Exception {
compileWithExpectedDiagnostics(
Main.class, diagnostics -> inspectDiagnosticsWithNoRules(diagnostics, referencedFrom));
}
@Test
public void testDontWarnMainClass() throws Exception {
compileWithExpectedDiagnostics(
Main.class, TestDiagnosticMessages::assertNoMessages, addDontWarn(Main.class));
}
@Test
public void testDontWarnMissingClass() throws Exception {
compileWithExpectedDiagnostics(
Main.class, TestDiagnosticMessages::assertNoMessages, addDontWarn(MissingClass.class));
}
@Test
public void testIgnoreWarnings() throws Exception {
compileWithExpectedDiagnostics(
Main.class,
diagnostics -> inspectDiagnosticsWithIgnoreWarnings(diagnostics, referencedFrom),
addIgnoreWarnings());
}
static class Main {
public static void main(String[] args) {
new Main().get(null);
}
public void get(MissingClass mc) {}
}
}