Files
kotlin-fork/compiler/testData/codegen/box/specialBuiltins/mapGetOrDefault.kt
T
Denis Zharkov 254380d418 Generate special bridges for removeAt/getOrDefault
In case we extending some Map specialization with non-trivial type arguments,
e.g. Map<String, String> from Kotlin point-of-view it has
"remove(String, String)" signature while in Java it's "remove(Object, Object)".

So, we generate an override "remove(String, String)" in first Kotlin class of the hierarchy,
which body delegates to "super.remove(Object, Object)"

Also, we generate a final override for "remove(Object, Object)" to allow
for Java inheritors choose only the version with String while overriding.

The main idea of the fix is to make mayBeUsedAsSuperImplementation
return true in case of PlatformDependent annotations.
Otherwise, we weren't able to choose the impl from the java.util.Map
as a delegate in our bridge.

Another part of the fix is overriding `isDeclaration`:
it was necessary because otherwise bridge-generation algorithm
was assuming that there's already an actual declaration
in the first sub-class (TestMap) in the test and we need to
delegate to the latter instead of the method from the interface

^KT-26069 Fixed
2019-01-14 14:54:18 +03:00

91 lines
1.4 KiB
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
// FILE: TestMap.java
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class TestMap implements Map<String, Object> {
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean containsKey(Object key) {
return false;
}
@Override
public boolean containsValue(Object value) {
return false;
}
@Override
public Object get(Object key) {
return null;
}
@Override
public Object put(String key, Object value) {
return null;
}
@Override
public Object remove(Object key) {
return null;
}
@Override
public void putAll(Map<? extends String, ?> m) {
}
@Override
public void clear() {
}
@Override
public Set<String> keySet() {
return null;
}
@Override
public Collection<Object> values() {
return null;
}
@Override
public Set<Entry<String, Object>> entrySet() {
return null;
}
}
// FILE: main.kt
class MyMap: TestMap()
fun box(): String {
val map = MyMap()
if (map.remove("aaa", 42)) return "fail 1"
if (map.getOrDefault("aaa", 42) != 42) return "fail 2"
return "OK"
}