[NI] Introduce feature for passing function references with defaults

Relates to KT-8834, we continue reducing differences between old and new
 inference. Note that as for `SamConversionPerArgument`, this feature
 is enabled in the compiler and not in the IDE to avoid breaking code
 for those users that already enabled new inference in the compiler
This commit is contained in:
Mikhail Zarechenskiy
2019-08-07 10:09:12 +03:00
parent 0219b86d06
commit 04e57f712e
29 changed files with 171 additions and 23 deletions
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/functionReferenceWithDefaultValuesFeatureIsEnabledWithNewInference.kt
-d
$TEMP_DIR$
-Xnew-inference
@@ -0,0 +1,11 @@
fun foo(a: String, b: Int = 5): String {
return a + b
}
fun bar1(body: (String) -> String): String {
return body("something")
}
fun test() {
bar1(::foo)
}
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/functionReferenceWithDefaultValuesFeatureIsEnabledWithNewInference.kt
-d
$TEMP_DIR$
-XXLanguage\:+NewInference
@@ -0,0 +1,10 @@
warning: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NewInference
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
OK
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
fun foo(s: String = "kotlin", vararg t: String): Boolean {
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
// WITH_RUNTIME
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
fun foo(vararg a: String, result: String = "OK"): String =
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
fun foo(x: String, y: Char = 'K'): String = x + y
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
fun foo(x: String = "O", vararg y: String): String =
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS, JVM_IR
fun foo(vararg l: Long, s: String = "OK"): String =
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
fun call0(f: (String) -> String, x: String): String = f(x)
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
// WITH_RUNTIME
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
fun foo(x: String, y: String = "K"): String = x + y
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND: JS
fun foo(x: Int, s: Int, vararg y: CharSequence = arrayOf("Aaa")): String =
@@ -0,0 +1,18 @@
// !WITH_NEW_INFERENCE
fun foo(a: String, b: Int = 5): String {
return a + b
}
fun bar1(body: (String) -> String): String {
return body("something")
}
fun bar2(body: (String, Int) -> String): String {
return body("something", 0)
}
fun test() {
bar1(<!NI;UNSUPPORTED_FEATURE, OI;TYPE_MISMATCH!>::foo<!>)
bar2(::foo)
}
@@ -0,0 +1,6 @@
package
public fun bar1(/*0*/ body: (kotlin.String) -> kotlin.String): kotlin.String
public fun bar2(/*0*/ body: (kotlin.String, kotlin.Int) -> kotlin.String): kotlin.String
public fun foo(/*0*/ a: kotlin.String, /*1*/ b: kotlin.Int = ...): kotlin.String
public fun test(): kotlin.Unit
@@ -0,0 +1,18 @@
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
fun foo(a: String, b: Int = 5): String {
return a + b
}
fun bar1(body: (String) -> String): String {
return body("something")
}
fun bar2(body: (String, Int) -> String): String {
return body("something", 0)
}
fun test() {
bar1(::foo)
bar2(::foo)
}
@@ -0,0 +1,6 @@
package
public fun bar1(/*0*/ body: (kotlin.String) -> kotlin.String): kotlin.String
public fun bar2(/*0*/ body: (kotlin.String, kotlin.Int) -> kotlin.String): kotlin.String
public fun foo(/*0*/ a: kotlin.String, /*1*/ b: kotlin.Int = ...): kotlin.String
public fun test(): kotlin.Unit