Fix desugar lib static itf calls N
Bug:134732760
Change-Id: Ifa665f430bf2652b97b51524c7b58f4a291305db
diff --git a/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java b/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java
index 3f31b74..344a7b5 100644
--- a/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java
+++ b/src/main/java/com/android/tools/r8/ir/conversion/IRConverter.java
@@ -215,9 +215,12 @@
// InterfaceMethodRewriter is needed for emulated interfaces.
// LambdaRewriter is needed because if it is missing there are invoke custom on
// default/static interface methods, and this is not supported by the compiler.
- // The rest is nulled out.
+ // The rest is nulled out. In addition the rewriting logic fails without lambda rewritting.
this.backportedMethodRewriter = new BackportedMethodRewriter(appView, this);
- this.interfaceMethodRewriter = new InterfaceMethodRewriter(appView, this);
+ this.interfaceMethodRewriter =
+ options.desugaredLibraryConfiguration.getEmulateLibraryInterface().isEmpty()
+ ? null
+ : new InterfaceMethodRewriter(appView, this);
this.lambdaRewriter = new LambdaRewriter(appView, this);
this.twrCloseResourceRewriter = null;
this.lambdaMerger = null;
diff --git a/src/test/java/com/android/tools/r8/desugar/corelib/StaticInterfaceMethodTest.java b/src/test/java/com/android/tools/r8/desugar/corelib/StaticInterfaceMethodTest.java
new file mode 100644
index 0000000..aafd39f
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/desugar/corelib/StaticInterfaceMethodTest.java
@@ -0,0 +1,50 @@
+// Copyright (c) 2019, 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.corelib;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.StringUtils;
+import java.time.chrono.Chronology;
+import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class StaticInterfaceMethodTest extends CoreLibDesugarTestBase {
+
+ private final TestParameters parameters;
+
+ @Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withDexRuntimes().withAllApiLevels().build();
+ }
+
+ public StaticInterfaceMethodTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void testStaticInterfaceMethods() throws Exception {
+ testForD8()
+ .addInnerClasses(StaticInterfaceMethodTest.class)
+ .setMinApi(parameters.getApiLevel())
+ .enableCoreLibraryDesugaring(parameters.getApiLevel())
+ .compile()
+ .addDesugaredCoreLibraryRunClassPath(this::buildDesugaredLibrary, parameters.getApiLevel())
+ .run(parameters.getRuntime(), Executor.class)
+ .assertSuccessWithOutput(StringUtils.lines("false", "java.util.HashSet"));
+ }
+
+ static class Executor {
+
+ public static void main(String[] args) {
+ System.out.println(Map.Entry.comparingByKey() == null);
+ System.out.println(Chronology.getAvailableChronologies().getClass().getName());
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/desugar/corelib/corelibjdktests/Jdk11TimeTests.java b/src/test/java/com/android/tools/r8/desugar/corelib/corelibjdktests/Jdk11TimeTests.java
index 9fa021d..28adca8 100644
--- a/src/test/java/com/android/tools/r8/desugar/corelib/corelibjdktests/Jdk11TimeTests.java
+++ b/src/test/java/com/android/tools/r8/desugar/corelib/corelibjdktests/Jdk11TimeTests.java
@@ -129,8 +129,6 @@
@Test
public void testTime() throws Exception {
- // TODO(b/134732760): Fix calls to CC static methods.
- Assume.assumeTrue(parameters.getApiLevel().getLevel() != 24);
String verbosity = "2";
D8TestCompileResult compileResult =
testForD8()