JVM_IR: Fix Inline CallableReferences with Varargs
- Added tests to demonstrate broken behaviour: the interaction of inline functions and callable references with varargs and defaults in various combinations. - Refactored InlineCallableReferencesToLambdaPhase to look like and use some of the infrastructure from CallableReferenceLowering. - Lifted some of this infrastructure out to be broadly reusable.
This commit is contained in:
committed by
Mikhael Bogdanov
parent
5360a7a3fe
commit
1074a0ef69
+11
@@ -0,0 +1,11 @@
|
||||
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
|
||||
inline fun foo(mkString: () -> String): String =
|
||||
mkString()
|
||||
|
||||
fun bar (xs: CharArray = charArrayOf('O','K')) =
|
||||
String(xs)
|
||||
|
||||
fun box(): String = foo(::bar)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JS, JS_IR
|
||||
|
||||
inline fun foo(mkString: (Char, Char) -> String): String =
|
||||
mkString('O','K')
|
||||
|
||||
fun bar (vararg xs: Char) =
|
||||
String(xs)
|
||||
|
||||
fun box(): String = foo(::bar)
|
||||
// -> { a, b -> bar(a, b) }
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
|
||||
// IGNORE_BACKEND: JS, JVM_IR, JS_IR
|
||||
// IGNORE_BACKEND: JS, JS_IR
|
||||
|
||||
fun foo(vararg l: Long, s: String = "OK"): String =
|
||||
if (l.size == 0) s else "Fail"
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JS, JS_IR
|
||||
|
||||
inline fun foo(x: (Int, Int) -> Int): Int =
|
||||
x(120,3)
|
||||
|
||||
fun bar(vararg x: Int): Int =
|
||||
x.sum()
|
||||
|
||||
fun box(): String =
|
||||
if (foo(::bar) == 123) "OK" else "FAIL"
|
||||
Reference in New Issue
Block a user