JVM IR: fix incorrect detection of interface method impls in Java

The problem in the test case was that `JImpl.entrySet` was detected by
ReplaceDefaultImplsOverriddenSymbols as a class fake override, which
overrides non-abstract interface method. Thus, overriddenSymbols of
`MyMap.entrySet` were changed in
`ReplaceDefaultImplsOverriddenSymbols.visitSimpleFunction`.

Later, BridgeLowering tried to determine which special bridges to
generate for `MyMap.<get-entries>`, and for that it inspected existing
methods and their overrides.

Normally we would generate the following special bridge:

    getEntries()Ljava/util/Set;
        invokespecial JImpl.entrySet()Ljava/util/Set;

However, because of incorrect overrides, the generated class method was
selected here instead of the expected `Map.<get-entries>`:
https://github.com/JetBrains/kotlin/blob/06001fc0919c814e757caa494891619882fae15f/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt#L282
and since the JVM signature of the generated class method is the same as
that of the fake override in MyMap, we never got to generating the
special bridge.

The solution is to skip Java classes when looking for class methods
which override non-abstract interface methods. This logic only makes
sense for Kotlin code, because only Kotlin has DefaultImpls, and the
requirement to generate non-abstract fake overrides of interface methods
as actual methods in the bytecode, delegating to DefaultImpls.

 #KT-48167 Fixed
This commit is contained in:
Alexander Udalov
2021-08-11 22:44:51 +02:00
parent d124239025
commit 1b98723b3f
11 changed files with 220 additions and 1 deletions
@@ -32423,6 +32423,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/specialBuiltins/irrelevantRemoveAtOverride.kt");
}
@TestMetadata("javaMapWithCustomEntries.kt")
public void testJavaMapWithCustomEntries() throws Exception {
runTest("compiler/testData/codegen/box/specialBuiltins/javaMapWithCustomEntries.kt");
}
@TestMetadata("mapGetOrDefault.kt")
public void testMapGetOrDefault() throws Exception {
runTest("compiler/testData/codegen/box/specialBuiltins/mapGetOrDefault.kt");