mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-23 08:31:33 +00:00
[NI] Disable SAM-conversions for Kotlin functions by default
#KT-30661 Fixed
This commit is contained in:
@@ -305,7 +305,6 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
|
||||
if (newInference) {
|
||||
put(LanguageFeature.NewInference, LanguageFeature.State.ENABLED)
|
||||
put(LanguageFeature.SamConversionForKotlinFunctions, LanguageFeature.State.ENABLED)
|
||||
}
|
||||
|
||||
if (legacySmartCastAfterTry) {
|
||||
@@ -343,22 +342,13 @@ 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,
|
||||
|
||||
@@ -17975,6 +17975,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/samConversions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("checkSamConversionsAreDisabledByDefault.kt")
|
||||
public void testCheckSamConversionsAreDisabledByDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DisabledForKTSimple.kt")
|
||||
public void testDisabledForKTSimple() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.kt");
|
||||
|
||||
@@ -60,7 +60,8 @@ class SamAdapterFunctionsScope(
|
||||
private val deprecationResolver: DeprecationResolver,
|
||||
private val lookupTracker: LookupTracker
|
||||
) : SyntheticScope.Default() {
|
||||
private val samViaSyntheticScopeDisabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
|
||||
private val samViaSyntheticScopeDisabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference) &&
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.SamConversionForKotlinFunctions)
|
||||
|
||||
private val extensionForFunction =
|
||||
storageManager.createMemoizedFunctionWithNullableValues<FunctionDescriptor, FunctionDescriptor> { function ->
|
||||
|
||||
@@ -7,7 +7,7 @@ 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) {}
|
||||
compiler/testData/cli/jvm/newInferenceImpliesSamConversions.kt:4:9: error: type mismatch: inferred type is () -> TypeVariable(_L) but Runnable was expected
|
||||
foo { }
|
||||
^
|
||||
OK
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
compiler/testData/cli/jvm/newInferenceImpliesSamConversions.kt:1:9: warning: parameter 'r' is never used
|
||||
fun foo(r: Runnable) {}
|
||||
compiler/testData/cli/jvm/newInferenceImpliesSamConversions.kt:4:9: error: type mismatch: inferred type is () -> TypeVariable(_L) but Runnable was expected
|
||||
foo { }
|
||||
^
|
||||
OK
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -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, 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, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
|
||||
foo(x, ::bar)
|
||||
|
||||
complex(x, ::bar)
|
||||
|
||||
31
compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt
vendored
Normal file
31
compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// FILE: Runnable.java
|
||||
public interface Runnable {
|
||||
void run();
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
interface K {
|
||||
fun foo1(r: Runnable)
|
||||
fun foo2(r1: Runnable, r2: Runnable)
|
||||
fun foo3(r1: Runnable, r2: Runnable, r3: Runnable)
|
||||
}
|
||||
fun test(k: K, r: Runnable) {
|
||||
k.foo1(r)
|
||||
k.foo1(<!TYPE_MISMATCH!>{}<!>)
|
||||
|
||||
k.foo2(r, r)
|
||||
k.foo2(<!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>)
|
||||
k.foo2(r, <!TYPE_MISMATCH!>{}<!>)
|
||||
k.foo2(<!TYPE_MISMATCH!>{}<!>, r)
|
||||
|
||||
k.foo3(r, r, r)
|
||||
k.foo3(r, r, <!TYPE_MISMATCH!>{}<!>)
|
||||
k.foo3(r, <!TYPE_MISMATCH!>{}<!>, r)
|
||||
k.foo3(r, <!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>)
|
||||
k.foo3(<!TYPE_MISMATCH!>{}<!>, r, r)
|
||||
k.foo3(<!TYPE_MISMATCH!>{}<!>, r, <!TYPE_MISMATCH!>{}<!>)
|
||||
k.foo3(<!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>, r)
|
||||
k.foo3(<!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>, <!TYPE_MISMATCH!>{}<!>)
|
||||
}
|
||||
19
compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.txt
vendored
Normal file
19
compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.txt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ k: K, /*1*/ r: Runnable): kotlin.Unit
|
||||
|
||||
public interface K {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo1(/*0*/ r: Runnable): kotlin.Unit
|
||||
public abstract fun foo2(/*0*/ r1: Runnable, /*1*/ r2: Runnable): kotlin.Unit
|
||||
public abstract fun foo3(/*0*/ r1: Runnable, /*1*/ r2: Runnable, /*2*/ r3: Runnable): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Runnable {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract fun run(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -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<!> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17987,6 +17987,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/samConversions"), Pattern.compile("^(.*)\\.kts?$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("checkSamConversionsAreDisabledByDefault.kt")
|
||||
public void testCheckSamConversionsAreDisabledByDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DisabledForKTSimple.kt")
|
||||
public void testDisabledForKTSimple() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.kt");
|
||||
|
||||
@@ -17977,6 +17977,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/samConversions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("checkSamConversionsAreDisabledByDefault.kt")
|
||||
public void testCheckSamConversionsAreDisabledByDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DisabledForKTSimple.kt")
|
||||
public void testDisabledForKTSimple() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/DisabledForKTSimple.kt");
|
||||
|
||||
Reference in New Issue
Block a user