Enable SAM conversion for Kotlin functions by default in new inference

KT-25686
This commit is contained in:
Mikhail Zarechenskiy
2018-08-10 11:03:40 +03:00
parent 31a5746724
commit b1985ee422
11 changed files with 97 additions and 0 deletions
@@ -210,6 +210,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
if (newInference) {
put(LanguageFeature.NewInference, LanguageFeature.State.ENABLED)
put(LanguageFeature.SamConversionForKotlinFunctions, LanguageFeature.State.ENABLED)
}
if (legacySmartCastAfterTry) {
@@ -247,13 +248,22 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
private fun HashMap<LanguageFeature, LanguageFeature.State>.configureLanguageFeaturesFromInternalArgs(collector: MessageCollector) {
val featuresThatForcePreReleaseBinaries = mutableListOf<LanguageFeature>()
var samConversionsExplicitlyPassed = false
for ((feature, state) in internalArguments.filterIsInstance<ManualLanguageFeatureSetting>()) {
if (feature == LanguageFeature.SamConversionForKotlinFunctions) {
samConversionsExplicitlyPassed = true
}
put(feature, state)
if (state == LanguageFeature.State.ENABLED && feature.forcesPreReleaseBinariesIfEnabled()) {
featuresThatForcePreReleaseBinaries += feature
}
}
if (!samConversionsExplicitlyPassed && this[LanguageFeature.NewInference] == LanguageFeature.State.ENABLED) {
put(LanguageFeature.SamConversionForKotlinFunctions, LanguageFeature.State.ENABLED)
}
if (featuresThatForcePreReleaseBinaries.isNotEmpty()) {
collector.report(
CompilerMessageSeverity.STRONG_WARNING,
@@ -0,0 +1,5 @@
$TESTDATA_DIR$/newInferenceImpliesSamConversions.kt
-d
$TEMP_DIR$
-Xnew-inference
-XXLanguage\:-SamConversionForKotlinFunctions
@@ -0,0 +1,13 @@
warning: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:-SamConversionForKotlinFunctions
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!
compiler/testData/cli/jvm/newInferenceImpliesSamConversions.kt:4:9: error: type mismatch: inferred type is () -> TypeVariable(_L) but Runnable was expected
foo { }
^
COMPILATION_ERROR
@@ -0,0 +1,5 @@
$TESTDATA_DIR$/newInferenceImpliesSamConversions.kt
-d
$TEMP_DIR$
-XXLanguage\:+NewInference
-XXLanguage\:-SamConversionForKotlinFunctions
@@ -0,0 +1,14 @@
warning: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NewInference
-XXLanguage:-SamConversionForKotlinFunctions
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!
compiler/testData/cli/jvm/newInferenceImpliesSamConversions.kt:4:9: error: type mismatch: inferred type is () -> TypeVariable(_L) but Runnable was expected
foo { }
^
COMPILATION_ERROR
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/newInferenceImpliesSamConversions.kt
-d
$TEMP_DIR$
-XXLanguage\:+NewInference
@@ -0,0 +1,5 @@
fun foo(r: Runnable) {}
fun test() {
foo { }
}
@@ -0,0 +1,13 @@
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!
compiler/testData/cli/jvm/newInferenceImpliesSamConversions.kt:1:9: warning: parameter 'r' is never used
fun foo(r: Runnable) {}
^
OK
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/newInferenceImpliesSamConversions.kt
-d
$TEMP_DIR$
-Xnew-inference
@@ -0,0 +1,4 @@
compiler/testData/cli/jvm/newInferenceImpliesSamConversions.kt:1:9: warning: parameter 'r' is never used
fun foo(r: Runnable) {}
^
OK
@@ -206,6 +206,16 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/experimentalUnresolved.args");
}
@TestMetadata("explicitlyDisableSamConversionsWithOldFlag.args")
public void testExplicitlyDisableSamConversionsWithOldFlag() throws Exception {
runTest("compiler/testData/cli/jvm/explicitlyDisableSamConversionsWithOldFlag.args");
}
@TestMetadata("explicitlyDisabledSamConversions.args")
public void testExplicitlyDisabledSamConversions() throws Exception {
runTest("compiler/testData/cli/jvm/explicitlyDisabledSamConversions.args");
}
@TestMetadata("extraArgumentPassedInObsoleteForm.args")
public void testExtraArgumentPassedInObsoleteForm() throws Exception {
runTest("compiler/testData/cli/jvm/extraArgumentPassedInObsoleteForm.args");
@@ -416,6 +426,16 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.args");
}
@TestMetadata("newInferenceImpliesSamConversions.args")
public void testNewInferenceImpliesSamConversions() throws Exception {
runTest("compiler/testData/cli/jvm/newInferenceImpliesSamConversions.args");
}
@TestMetadata("newInferenceWithOldFlagImpliesSamConversions.args")
public void testNewInferenceWithOldFlagImpliesSamConversions() throws Exception {
runTest("compiler/testData/cli/jvm/newInferenceWithOldFlagImpliesSamConversions.args");
}
@TestMetadata("noReflect.args")
public void testNoReflect() throws Exception {
runTest("compiler/testData/cli/jvm/noReflect.args");