Add tests on coercion to Unit for callable references
#KT-11723
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// IGNORE_BACKEND: JS_IR, JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Foo
|
||||
|
||||
class Builder {
|
||||
var size: Int = 0
|
||||
|
||||
fun addFoo(foo: Foo): Builder {
|
||||
size++
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = Builder()
|
||||
listOf(Foo(), Foo(), Foo()).forEach(b::addFoo)
|
||||
return if (b.size == 3) "OK" else "Fail"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
fun foo(s: String): Boolean {
|
||||
if (s != "kotlin") throw AssertionError(s)
|
||||
return true
|
||||
}
|
||||
|
||||
fun bar(f: (String) -> Unit) {
|
||||
f("kotlin")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
bar(::foo)
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// IGNORE_BACKEND: JS, JS_IR, JVM_IR
|
||||
|
||||
fun foo(s: String = "kotlin", vararg t: String): Boolean {
|
||||
if (s != "kotlin") throw AssertionError(s)
|
||||
if (t.size != 0) throw AssertionError(t.size.toString())
|
||||
return true
|
||||
}
|
||||
|
||||
fun bar(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
bar(::foo)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user