diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 22d413ee3b4..577a58e9b1f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -560,20 +560,7 @@ class FirCallCompletionResultsWriterTransformer( // a built-in functional type, no-brainer expectedArgumentType.isSomeFunctionType(session) -> expectedArgumentType // fun interface (a.k.a. SAM), then unwrap it and build a functional type from that interface function - expectedArgumentType is ConeClassLikeType -> { - expectedArgumentType.lookupTag.toFirRegularClass(session)?.let answer@{ firRegularClass -> - val functionType = samResolver.getFunctionTypeForPossibleSamType(firRegularClass.defaultType()) - ?: return@answer null - val kind = functionType.functionTypeKind(session) ?: FunctionTypeKind.Function - createFunctionType( - kind, - functionType.typeArguments.dropLast(1).map { it as ConeKotlinType }, - null, - functionType.typeArguments.last() as ConeKotlinType - ) - } - } - else -> null + else -> samResolver.getFunctionTypeForPossibleSamType(expectedArgumentType)?.lowerBoundIfFlexible() } } diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java index 3afebc2009a..bdc1046f204 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated.java @@ -577,6 +577,11 @@ public class IncrementalFirICLightTreeJvmCompilerRunnerTestGenerated extends Abs runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java index 12d0c1f69e5..6eba482407e 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalFirLightTreeJvmCompilerRunnerTestGenerated.java @@ -577,6 +577,11 @@ public class IncrementalFirLightTreeJvmCompilerRunnerTestGenerated extends Abstr runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerRunnerTestGenerated.java index 50b1f205ffb..80dd5ef8500 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerRunnerTestGenerated.java @@ -591,6 +591,11 @@ public class IncrementalK1JsKlibCompilerRunnerTestGenerated extends AbstractIncr runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("secondaryConstructorInlined") public void testSecondaryConstructorInlined() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/"); diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java index de2677c1564..e67eb7d9d05 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java @@ -591,6 +591,11 @@ public class IncrementalK1JsKlibCompilerWithScopeExpansionRunnerTestGenerated ex runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("secondaryConstructorInlined") public void testSecondaryConstructorInlined() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/"); diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JvmCompilerRunnerTestGenerated.java index 4982fa8555f..6f40bd1d4cd 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK1JvmCompilerRunnerTestGenerated.java @@ -592,6 +592,11 @@ public class IncrementalK1JvmCompilerRunnerTestGenerated extends AbstractIncreme runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java index aefee850e4a..fe6de34e924 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JsKlibCompilerWithScopeExpansionRunnerTestGenerated.java @@ -586,6 +586,11 @@ public class IncrementalK2JsKlibCompilerWithScopeExpansionRunnerTestGenerated ex runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("secondaryConstructorInlined") public void testSecondaryConstructorInlined() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/secondaryConstructorInlined/"); diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestGenerated.java index 9e02e5dd70f..bb9e92cc514 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestGenerated.java @@ -577,6 +577,11 @@ public class IncrementalK2JvmCompilerRunnerTestGenerated extends AbstractIncreme runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK1JvmJpsTestGenerated.java b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK1JvmJpsTestGenerated.java index 7de1fef3a99..d207ec27cc4 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK1JvmJpsTestGenerated.java +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK1JvmJpsTestGenerated.java @@ -1261,6 +1261,11 @@ public class IncrementalK1JvmJpsTestGenerated extends AbstractIncrementalK1JvmJp runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2FirICLightTreeJvmJpsTestGenerated.java b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2FirICLightTreeJvmJpsTestGenerated.java index e7f3657adfa..0b5fa6b0279 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2FirICLightTreeJvmJpsTestGenerated.java +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2FirICLightTreeJvmJpsTestGenerated.java @@ -587,6 +587,11 @@ public class IncrementalK2FirICLightTreeJvmJpsTestGenerated extends AbstractIncr runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2JvmJpsTestGenerated.java b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2JvmJpsTestGenerated.java index a9c57410c86..db58e79c207 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2JvmJpsTestGenerated.java +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2JvmJpsTestGenerated.java @@ -587,6 +587,11 @@ public class IncrementalK2JvmJpsTestGenerated extends AbstractIncrementalK2JvmJp runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2LightTreeJvmJpsTestGenerated.java b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2LightTreeJvmJpsTestGenerated.java index eedd5a598c8..4e30d34c298 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2LightTreeJvmJpsTestGenerated.java +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalK2LightTreeJvmJpsTestGenerated.java @@ -587,6 +587,11 @@ public class IncrementalK2LightTreeJvmJpsTestGenerated extends AbstractIncrement runTest("jps/jps-plugin/testData/incremental/pureKotlin/returnTypeChanged/"); } + @TestMetadata("samConversion") + public void testSamConversion() throws Exception { + runTest("jps/jps-plugin/testData/incremental/pureKotlin/samConversion/"); + } + @TestMetadata("sealedClassesAddImplements") public void testSealedClassesAddImplements() throws Exception { runTest("jps/jps-plugin/testData/incremental/pureKotlin/sealedClassesAddImplements/"); diff --git a/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/build.log b/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/build.log new file mode 100644 index 00000000000..77f0247a91f --- /dev/null +++ b/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/build.log @@ -0,0 +1,13 @@ +================ Step #1 ================= + +Cleaning output files: + out/production/module/META-INF/module.kotlin_module + out/production/module/MainKt$main$1$1$1.class + out/production/module/MainKt$main$2.class + out/production/module/MainKt.class +End of files +Compiling files: + src/main.kt +End of files +Exit code: OK +------------------------------------------ diff --git a/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/main.kt b/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/main.kt new file mode 100644 index 00000000000..6922dd90dfc --- /dev/null +++ b/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/main.kt @@ -0,0 +1,17 @@ +fun main() { + Observable.of(1, 2) + .apply({ observable -> + Observable { subscriber -> + (observable).subscribe(object : Observer { + override fun next(value: Int) { + subscriber.next(value * 2) + } + + }) + } + }) + .subscribe(object : Subscriber() { + override fun next(value: Int) { + } + }) +} diff --git a/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/main.kt.touch b/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/main.kt.touch new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/observable.kt b/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/observable.kt new file mode 100644 index 00000000000..214447ff8ea --- /dev/null +++ b/jps/jps-plugin/testData/incremental/pureKotlin/samConversion/observable.kt @@ -0,0 +1,33 @@ +open class Subscription + +interface Observer { + fun next(value: T) +} + +open class Subscriber(observer: Observer? = null) : Subscription(), Observer { + override fun next(value: T) {} +} + +fun interface Subscribe { + fun subscribe(subscriber: Subscriber): Subscription +} + +fun interface Operator { + fun call(source: Observable): Observable +} + +open class Observable(private val subscribeFn: Subscribe) { + fun apply(operator: Operator): Observable { + return operator.call(this) + } + + fun subscribe(observer: Observer): Subscription { + return Subscription() + } + + companion object { + fun of(vararg elems: T): Observable { + return Observable { Subscription() } + } + } +}