7a9e1b2b1d
Report type mismatch on argument when a nullable argument is passed to non-null parameter. Note that this affects only functions with simple types without generics #KT-2007 Fixed #KT-9282 Fixed
43 lines
2.3 KiB
Plaintext
Vendored
43 lines
2.3 KiB
Plaintext
Vendored
fun valuesNotNull(map: MutableMap<Int, String>) {
|
|
map.merge(1, "x") { old, new -> old + new }
|
|
// SUCCESS
|
|
// ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap
|
|
// SUBSTITUTED: fun merge(Int, String, (String, String) -> String?): String? defined in kotlin.collections.MutableMap
|
|
}
|
|
|
|
fun valuesNullable(map: MutableMap<Int, String?>) {
|
|
map.merge(1, "x") { old, new -> old + new }
|
|
// SUCCESS
|
|
// ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap
|
|
// SUBSTITUTED: fun merge(Int, String, (String, String) -> String?): String? defined in kotlin.collections.MutableMap
|
|
map.merge(1, null) { old, new -> old + new }
|
|
// NULLABLE_ARGUMENT_TYPE_MISMATCH
|
|
// ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap
|
|
// SUBSTITUTED: fun merge(Int, String, (String, String) -> String?): String? defined in kotlin.collections.MutableMap
|
|
}
|
|
|
|
fun <T> valuesT(map: MutableMap<Int, T>, newValue: T) {
|
|
map.merge(1, newValue) { old, new -> null }
|
|
// SUCCESS
|
|
// ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap
|
|
// SUBSTITUTED: fun merge(Int, T, (T, T) -> T?): T? defined in kotlin.collections.MutableMap
|
|
}
|
|
|
|
fun <T : Any> valuesTNotNull(map: MutableMap<Int, T>, newValue: T) {
|
|
map.merge(1, newValue) { old, new -> null }
|
|
// SUCCESS
|
|
// ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap
|
|
// SUBSTITUTED: fun merge(Int, T, (T, T) -> T?): T? defined in kotlin.collections.MutableMap
|
|
}
|
|
|
|
fun <T : Any> valuesTNullable(map: MutableMap<Int, T?>, newValue: T?) {
|
|
map.merge(1, newValue) { old, new -> new }
|
|
// NULLABLE_ARGUMENT_TYPE_MISMATCH
|
|
// ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap
|
|
// SUBSTITUTED: fun merge(Int, T, (T, T) -> T?): T? defined in kotlin.collections.MutableMap
|
|
map.merge(1, newValue!!) { old, new -> new }
|
|
// SUCCESS
|
|
// ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap
|
|
// SUBSTITUTED: fun merge(Int, T, (T, T) -> T?): T? defined in kotlin.collections.MutableMap
|
|
}
|