Improve diagnostic on overload resolution ambiguity

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
This commit is contained in:
Mikhail Zarechenskiy
2017-06-20 17:18:53 +03:00
parent 16de991b07
commit 7a9e1b2b1d
11 changed files with 82 additions and 11 deletions
@@ -11,9 +11,9 @@ fun valuesNullable(map: MutableMap<Int, String?>) {
// 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 }
// OTHER_ERROR
// ORIGINAL: fun merge(K, V, BiFunction<in V, in V, out V?>): V? defined in kotlin.collections.MutableMap
// SUBSTITUTED: fun merge(Int, String, BiFunction<in String, in String, out String?>): String? defined in kotlin.collections.MutableMap
// 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) {
@@ -32,9 +32,9 @@ fun <T : Any> valuesTNotNull(map: MutableMap<Int, T>, newValue: T) {
fun <T : Any> valuesTNullable(map: MutableMap<Int, T?>, newValue: T?) {
map.merge(1, newValue) { old, new -> new }
// OTHER_ERROR
// ORIGINAL: fun merge(K, V, BiFunction<in V, in V, out V?>): V? defined in kotlin.collections.MutableMap
// SUBSTITUTED: fun merge(Int, T, BiFunction<in T, in T, out T?>): T? defined in kotlin.collections.MutableMap
// 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