Allow delegating val properties to out-projected MutableMap

Change generic signature of MutableMap.getValue, use 'out @Exact V' and `V1: V` types instead of single `in V`.
Fix affected IR generation tests.

#KT-18789 Fixed
This commit is contained in:
Ilya Gorbunov
2017-07-01 17:00:16 +03:00
parent e503c1d411
commit 7efaa7cabc
6 changed files with 18 additions and 7 deletions
@@ -5,6 +5,8 @@ import kotlin.test.*
class ValByMapExtensionsTest {
val map: Map<String, String> = hashMapOf("a" to "all", "b" to "bar", "c" to "code")
val genericMap = mapOf<String, Any?>("i" to 1, "x" to 1.0)
val mmapOut: MutableMap<String, out String> = mutableMapOf("g" to "out", "g1" to "in")
val genericMmapOut: MutableMap<String, out Any?> = mmapOut
val a by map
val b: String by map
@@ -12,6 +14,8 @@ class ValByMapExtensionsTest {
val d: String? by map
val e: String by map.withDefault { "default" }
val f: String? by map.withDefault { null }
val g: String by mmapOut
val g1: String by genericMmapOut
// val n: Int by map // prohibited by type system
val i: Int by genericMap
val x: Double by genericMap
@@ -23,6 +27,8 @@ class ValByMapExtensionsTest {
assertEquals("code", c)
assertEquals("default", e)
assertEquals(null, f)
assertEquals("out", g)
assertEquals("in", g1)
assertEquals(1, i)
assertEquals(1.0, x)
assertFailsWith<NoSuchElementException> { d }