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:
Denis Zharkov
2015-11-16 13:02:45 +03:00
parent 1f704e0c4d
commit fa99ea1e98
14 changed files with 226 additions and 29 deletions
@@ -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"
}