Generate type-safe barrier in method body
In cases when signature of special bridge is the same as current method, but type is not 'Any?'. Also there is tiny optimization: only null check needed if value parameter type is mapped to Object, but it's not nullable. #KT-9973 Fixed
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
private object NotEmptyMap : MutableMap<Any, Int> {
|
||||
override fun containsKey(key: Any): Boolean = true
|
||||
override fun containsValue(value: Int): Boolean = true
|
||||
|
||||
// non-special bridges get(Object)Integer -> get(Object)I
|
||||
override fun get(key: Any): Int = 1
|
||||
override fun remove(key: Any): Int = 1
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun put(key: Any, value: Int): Int? = throw UnsupportedOperationException()
|
||||
override fun putAll(from: Map<out Any, Int>): Unit = throw UnsupportedOperationException()
|
||||
override fun clear(): Unit = throw UnsupportedOperationException()
|
||||
override val entries: MutableSet<MutableMap.MutableEntry<Any, Int>> get() = null!!
|
||||
override val keys: MutableSet<Any> get() = null!!
|
||||
override val values: MutableCollection<Int> get() = null!!
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val n = NotEmptyMap as MutableMap<Any?, Any?>
|
||||
|
||||
if (n.get(null) != null) return "fail 1"
|
||||
if (n.containsKey(null)) return "fail 2"
|
||||
if (n.containsValue(null)) return "fail 3"
|
||||
if (n.remove(null) != null) return "fail 4"
|
||||
|
||||
if (n.get(1) == null) return "fail 5"
|
||||
if (!n.containsKey("")) return "fail 6"
|
||||
if (!n.containsValue(3)) return "fail 7"
|
||||
if (n.remove("") == null) return "fail 8"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
private object NotEmptyList : MutableList<Any> {
|
||||
override fun contains(element: Any): Boolean = true
|
||||
override fun indexOf(element: Any): Int = 0
|
||||
override fun lastIndexOf(element: Any): Int = 0
|
||||
override fun remove(element: Any): Boolean = true
|
||||
|
||||
override val size: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
override fun containsAll(elements: Collection<Any>): Boolean = elements.isEmpty()
|
||||
override fun isEmpty(): Boolean = throw UnsupportedOperationException()
|
||||
override fun get(index: Int): Any = throw UnsupportedOperationException()
|
||||
override fun add(element: Any): Boolean = throw UnsupportedOperationException()
|
||||
override fun addAll(elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
|
||||
override fun addAll(index: Int, elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
|
||||
override fun removeAll(elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
|
||||
override fun retainAll(elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
|
||||
override fun clear(): Unit = throw UnsupportedOperationException()
|
||||
override fun set(index: Int, element: Any): Any = throw UnsupportedOperationException()
|
||||
override fun add(index: Int, element: Any): Unit = throw UnsupportedOperationException()
|
||||
override fun removeAt(index: Int): Any = throw UnsupportedOperationException()
|
||||
override fun listIterator(): MutableListIterator<Any> = throw UnsupportedOperationException()
|
||||
override fun listIterator(index: Int): MutableListIterator<Any> = throw UnsupportedOperationException()
|
||||
override fun subList(fromIndex: Int, toIndex: Int): MutableList<Any> = throw UnsupportedOperationException()
|
||||
override fun iterator(): MutableIterator<Any> = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val n = NotEmptyList as MutableList<Any?>
|
||||
|
||||
if (n.contains(null)) return "fail 1"
|
||||
if (n.indexOf(null) != -1) return "fail 2"
|
||||
if (n.lastIndexOf(null) != -1) return "fail 3"
|
||||
|
||||
if (!n.contains("")) return "fail 3"
|
||||
if (n.indexOf("") != 0) return "fail 4"
|
||||
if (n.lastIndexOf("") != 0) return "fail 5"
|
||||
|
||||
if (n.remove(null)) return "fail 6"
|
||||
if (!n.remove("")) return "fail 7"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
private object NotEmptyMap : MutableMap<Any, Any> {
|
||||
override fun containsKey(key: Any): Boolean = true
|
||||
override fun containsValue(value: Any): Boolean = true
|
||||
override fun get(key: Any): Any? = Any()
|
||||
override fun remove(key: Any): Any? = Any()
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = true
|
||||
override fun put(key: Any, value: Any): Any? = throw UnsupportedOperationException()
|
||||
override fun putAll(from: Map<out Any, Any>): Unit = throw UnsupportedOperationException()
|
||||
override fun clear(): Unit = throw UnsupportedOperationException()
|
||||
override val entries: MutableSet<MutableMap.MutableEntry<Any, Any>> get() = null!!
|
||||
override val keys: MutableSet<Any> get() = null!!
|
||||
override val values: MutableCollection<Any> get() = null!!
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val n = NotEmptyMap as MutableMap<Any?, Any?>
|
||||
|
||||
if (n.get(null) != null) return "fail 1"
|
||||
if (n.containsKey(null)) return "fail 2"
|
||||
if (n.containsValue(null)) return "fail 3"
|
||||
if (n.remove(null) != null) return "fail 4"
|
||||
|
||||
if (n.get("") == null) return "fail 5"
|
||||
if (!n.containsKey("")) return "fail 6"
|
||||
if (!n.containsValue("")) return "fail 7"
|
||||
if (n.remove("") == null) return "fail 8"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user