KT-6244 Overloads with no default parameters should take over ones with defaults

#KT-6244 Fixed
This commit is contained in:
Stanislav Erokhin
2015-08-31 22:07:37 +03:00
parent 5ded315cbb
commit d015f713cb
14 changed files with 99 additions and 16 deletions
@@ -0,0 +1,59 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
fun simple() = 1
fun simple(a: Int = 3) = ""
fun twoDefault(a: Int = 2) = 1
fun twoDefault(a: Any = 2, b: String = "") = ""
fun <T> withGeneric(a: T) = 1
fun <T> withGeneric(a: T, b: Int = 4) = ""
fun <T> discriminateGeneric(a: T) = 1
fun discriminateGeneric(a: Int, b: String = "") = ""
fun <T: CharSequence> withDefaultGeneric(t: T, d: T? = null) = 1
fun <T: Any> withDefaultGeneric(t: T, d: T? = null, a: Int = 1) = ""
fun wrongTwoDefault(a: Any = 2) = 1
fun wrongTwoDefault(a: Int = 2, b: String = "") = ""
fun <T: Any> wrongWithDefaultGeneric(t: T, d: T? = null) = 1
fun <T: CharSequence> wrongWithDefaultGeneric(t: T, d: T? = null, a: Int = 1) = ""
fun wrong(a: Int = 1) {}
fun wrong(a: String = "", b: Int = 1) {}
fun test() {
val a = simple()
a checkType { _<Int>() }
val b = simple(1)
b checkType { _<String>() }
val c = twoDefault()
c checkType { _<Int>() }
val d = twoDefault(1)
d checkType { _<Int>() }
val e = twoDefault(1, "")
e checkType { _<String>() }
val f = withGeneric(3)
f checkType { _<Int>() }
val g = discriminateGeneric(1)
g checkType { _<String>() }
val h = withDefaultGeneric("")
h checkType { _<Int>() }
<!OVERLOAD_RESOLUTION_AMBIGUITY!>wrongTwoDefault<!>(1)
<!CANNOT_COMPLETE_RESOLVE!>wrongWithDefaultGeneric<!>("")
<!UNREACHABLE_CODE!><!OVERLOAD_RESOLUTION_AMBIGUITY!>wrong<!>(<!>null!!<!UNREACHABLE_CODE!>)<!>
}
@@ -0,0 +1,19 @@
package
internal fun </*0*/ T> discriminateGeneric(/*0*/ a: T): kotlin.Int
internal fun discriminateGeneric(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.String = ...): kotlin.String
internal fun simple(): kotlin.Int
internal fun simple(/*0*/ a: kotlin.Int = ...): kotlin.String
internal fun test(): kotlin.Unit
internal fun twoDefault(/*0*/ a: kotlin.Any = ..., /*1*/ b: kotlin.String = ...): kotlin.String
internal fun twoDefault(/*0*/ a: kotlin.Int = ...): kotlin.Int
internal fun </*0*/ T : kotlin.CharSequence> withDefaultGeneric(/*0*/ t: T, /*1*/ d: T? = ...): kotlin.Int
internal fun </*0*/ T : kotlin.Any> withDefaultGeneric(/*0*/ t: T, /*1*/ d: T? = ..., /*2*/ a: kotlin.Int = ...): kotlin.String
internal fun </*0*/ T> withGeneric(/*0*/ a: T): kotlin.Int
internal fun </*0*/ T> withGeneric(/*0*/ a: T, /*1*/ b: kotlin.Int = ...): kotlin.String
internal fun wrong(/*0*/ a: kotlin.Int = ...): kotlin.Unit
internal fun wrong(/*0*/ a: kotlin.String = ..., /*1*/ b: kotlin.Int = ...): kotlin.Unit
internal fun wrongTwoDefault(/*0*/ a: kotlin.Any = ...): kotlin.Int
internal fun wrongTwoDefault(/*0*/ a: kotlin.Int = ..., /*1*/ b: kotlin.String = ...): kotlin.String
internal fun </*0*/ T : kotlin.Any> wrongWithDefaultGeneric(/*0*/ t: T, /*1*/ d: T? = ...): kotlin.Int
internal fun </*0*/ T : kotlin.CharSequence> wrongWithDefaultGeneric(/*0*/ t: T, /*1*/ d: T? = ..., /*2*/ a: kotlin.Int = ...): kotlin.String