diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 8c939b69dce..001ee7175af 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -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.configureLanguageFeaturesFromInternalArgs(collector: MessageCollector) { val featuresThatForcePreReleaseBinaries = mutableListOf() - var samConversionsExplicitlyPassed = false for ((feature, state) in internalArguments.filterIsInstance()) { - 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, diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index 181674aef7b..cf1ea12de31 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -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"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index acea1170180..f062ea2dbb3 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.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 { function -> diff --git a/compiler/testData/cli/jvm/newInferenceImpliesSamConversions.out b/compiler/testData/cli/jvm/newInferenceImpliesSamConversions.out index ab51f06e1c5..34ff1424cbb 100644 --- a/compiler/testData/cli/jvm/newInferenceImpliesSamConversions.out +++ b/compiler/testData/cli/jvm/newInferenceImpliesSamConversions.out @@ -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 diff --git a/compiler/testData/cli/jvm/newInferenceWithOldFlagImpliesSamConversions.out b/compiler/testData/cli/jvm/newInferenceWithOldFlagImpliesSamConversions.out index 45e1b102f14..c99f1bda73c 100644 --- a/compiler/testData/cli/jvm/newInferenceWithOldFlagImpliesSamConversions.out +++ b/compiler/testData/cli/jvm/newInferenceWithOldFlagImpliesSamConversions.out @@ -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 diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt b/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt index fbe342c6e36..6bf8bbf1615 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt @@ -16,14 +16,14 @@ fun bar(s: T) {} fun complex(t: T, f: (T) -> Unit) {} fun test1() { - foo(1, 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 test2(x: R) { - foo(x, 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) diff --git a/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt b/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt new file mode 100644 index 00000000000..92b190304ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.kt @@ -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({}) + + k.foo2(r, r) + k.foo2({}, {}) + k.foo2(r, {}) + k.foo2({}, r) + + k.foo3(r, r, r) + k.foo3(r, r, {}) + k.foo3(r, {}, r) + k.foo3(r, {}, {}) + k.foo3({}, r, r) + k.foo3({}, r, {}) + k.foo3({}, {}, r) + k.foo3({}, {}, {}) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.txt b/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.txt new file mode 100644 index 00000000000..5ca15fd90d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/samConversions/checkSamConversionsAreDisabledByDefault.txt @@ -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 +} diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt index 308acfa0c82..f0e62c09462 100644 --- a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt @@ -21,7 +21,7 @@ class B : A() { } if (d.x is B) { - d.x.foo {} + d.x.foo {} } } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index b015a645273..451456d2fad 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index e7fd466611c..5352e99d1f7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -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");