[NI] Move ability to convert standalone SAM-argument under the feature

If new inference is enabled only for IDE analysis, then this feature
 will be disabled to reduce difference between new and old inference,
 but if new inference is enabled in the compiler, then this feature
 will be enabled too to preserve behavior of new inference for
 compilation

 #KT-32175 Fixed
 #KT-32143 Fixed
 #KT-32123 Fixed
 #KT-32230 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-06-25 20:01:36 +03:00
parent 4d82b02f83
commit c2cf4aa2b5
34 changed files with 151 additions and 34 deletions
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/standaloneSamConversionsAreEnabledWithNewInference.kt
-d
$TEMP_DIR$
-Xnew-inference -XXLanguage:-SamConversionPerArgument
@@ -0,0 +1,8 @@
warning: flag is not supported by this version of the compiler: -Xnew-inference -XXLanguage:-SamConversionPerArgument
compiler/testData/cli/jvm/standaloneSamConversionsAreEnabledWithNewInference.kt:9:25: error: type mismatch: inferred type is () -> Unit but Runnable was expected
ForceSam.compare(r, {})
^
compiler/testData/cli/jvm/standaloneSamConversionsAreEnabledWithNewInference.kt:10:22: error: type mismatch: inferred type is () -> Unit but Runnable was expected
ForceSam.compare({}, r)
^
COMPILATION_ERROR
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/standaloneSamConversionsAreEnabledWithNewInference.kt
-d
$TEMP_DIR$
-Xnew-inference
@@ -0,0 +1,11 @@
object ForceSam : java.util.Comparator<Runnable> {
override fun compare(o1: Runnable, o2: Runnable): Int = 0
}
fun test(r: Runnable) {
ForceSam.compare(r, r)
ForceSam.compare({}, {})
ForceSam.compare(r, {})
ForceSam.compare({}, r)
}
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/standaloneSamConversionsAreEnabledWithNewInference.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
@@ -0,0 +1,3 @@
$TESTDATA_DIR$/standaloneSamConversionsAreEnabledWithNewInference.kt
-d
$TEMP_DIR$
@@ -0,0 +1,7 @@
compiler/testData/cli/jvm/standaloneSamConversionsAreEnabledWithNewInference.kt:9:25: error: type mismatch: inferred type is () -> Unit but Runnable was expected
ForceSam.compare(r, {})
^
compiler/testData/cli/jvm/standaloneSamConversionsAreEnabledWithNewInference.kt:10:22: error: type mismatch: inferred type is () -> Unit but Runnable was expected
ForceSam.compare({}, r)
^
COMPILATION_ERROR
@@ -1,6 +1,5 @@
// !LANGUAGE: +NewInference
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: example/Hello.java
+1 -1
View File
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +SamConversionPerArgument
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
+1 -1
View File
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
@@ -1,4 +1,4 @@
// !WITH_NEW_INFERENCE
// !LANGUAGE: +SamConversionPerArgument +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: A.java
@@ -16,14 +16,14 @@ fun <T> bar(s: T) {}
fun <T> complex(t: T, f: (T) -> Unit) {}
fun test1() {
foo(1, <!NI;TYPE_MISMATCH!>A::invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
foo(1, <!TYPE_MISMATCH!>A::invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
foo(1, ::bar)
complex(1, ::bar)
}
fun <R> test2(x: R) {
foo(x, <!NI;TYPE_MISMATCH!>A::invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
foo(x, <!TYPE_MISMATCH!>A::invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
foo(x, ::bar)
complex(x, ::bar)
@@ -13,5 +13,5 @@ public class J {
package test
fun test() {
J("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = { }, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
J("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = <!NI;TYPE_MISMATCH!>{ }<!>, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
}
@@ -13,5 +13,5 @@ public class J {
package test
fun test() {
J.foo("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = { }, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
J.foo("", <!NAMED_ARGUMENTS_NOT_ALLOWED!>r<!> = <!NI;TYPE_MISMATCH!>{ }<!>, <!NAMED_ARGUMENTS_NOT_ALLOWED!>z<!> = false)
}
@@ -21,7 +21,7 @@ class B {
fun main() {
fun println() {}
// All parameters in SAM adapter of `foo` have functional types
B().foo(<!OI;TYPE_MISMATCH!>{ println() }<!>, B.bar())
B().foo(<!TYPE_MISMATCH!>{ println() }<!>, B.bar())
// So you should use SAM constructors when you want to use mix lambdas and Java objects
B().foo(Runnable { println() }, B.bar())
B().foo({ println() }, { it: Any? -> it == null } )
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference
// !LANGUAGE: +NewInference +SamConversionPerArgument
// !CHECK_TYPE
// FILE: J.java
public interface J<T> {
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument
// !CHECK_TYPE
// FILE: F.java
public interface F<S> {
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument
// !CHECK_TYPE
// FILE: Fn.java
public interface Fn<T, R> {
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// !LANGUAGE: +NewInference +SamConversionPerArgument
// FILE: J.java
public interface J {
public void foo1(Runnable r);
@@ -1,4 +1,4 @@
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions +SamConversionPerArgument
// FILE: Runnable.java
public interface Runnable {
void run();
@@ -21,7 +21,7 @@ class B : A() {
}
if (d.x is B) {
<!OI;SMARTCAST_IMPOSSIBLE!>d.x<!>.<!NI;INVISIBLE_MEMBER!>foo<!> {}
<!SMARTCAST_IMPOSSIBLE!>d.x<!>.<!NI;INVISIBLE_MEMBER!>foo<!> {}
}
}
}
@@ -2,7 +2,7 @@
// FILE: KotlinFile.kt
fun foo(javaClass: JavaClass<Int>): Int {
val inner = javaClass.createInner<String>()
return <!TYPE_MISMATCH!>inner.doSomething(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, "") <!OI;TYPE_MISMATCH!>{ }<!><!>
return <!TYPE_MISMATCH!>inner.<!NI;TYPE_MISMATCH!>doSomething(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, "") <!TYPE_MISMATCH!>{ }<!><!><!>
}
// FILE: JavaClass.java
@@ -1,9 +1,9 @@
// !WITH_NEW_INFERENCE
// FILE: KotlinFile.kt
fun foo(javaClass: JavaClass) {
javaClass.doSomething(<!NAMED_ARGUMENTS_NOT_ALLOWED!>p<!> = 1) {
javaClass.doSomething(<!NAMED_ARGUMENTS_NOT_ALLOWED!>p<!> = 1) <!NI;TYPE_MISMATCH!>{
bar()
}
}<!>
}
fun bar(){}
@@ -1,7 +1,7 @@
// !WITH_NEW_INFERENCE
// FILE: KotlinFile.kt
fun foo(javaClass: JavaClass) {
javaClass.<!INVISIBLE_MEMBER!>doSomething<!> <!OI;TYPE_MISMATCH!>{ }<!>
javaClass.<!INVISIBLE_MEMBER!>doSomething<!> <!TYPE_MISMATCH!>{ }<!>
}
// FILE: JavaClass.java