[FIR] Fix generic sam conversion in call completion
#KT-60903 Fixed
This commit is contained in:
committed by
Space Team
parent
3ecadf1af7
commit
43180597fe
+1
-14
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
Generated
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
Generated
+5
@@ -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/");
|
||||
|
||||
+5
@@ -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/");
|
||||
|
||||
@@ -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
|
||||
------------------------------------------
|
||||
@@ -0,0 +1,17 @@
|
||||
fun main() {
|
||||
Observable.of(1, 2)
|
||||
.apply({ observable ->
|
||||
Observable { subscriber ->
|
||||
(observable).subscribe(object : Observer<Int> {
|
||||
override fun next(value: Int) {
|
||||
subscriber.next(value * 2)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
})
|
||||
.subscribe(object : Subscriber<Int>() {
|
||||
override fun next(value: Int) {
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
open class Subscription
|
||||
|
||||
interface Observer<T> {
|
||||
fun next(value: T)
|
||||
}
|
||||
|
||||
open class Subscriber<T>(observer: Observer<T>? = null) : Subscription(), Observer<T> {
|
||||
override fun next(value: T) {}
|
||||
}
|
||||
|
||||
fun interface Subscribe<T> {
|
||||
fun subscribe(subscriber: Subscriber<T>): Subscription
|
||||
}
|
||||
|
||||
fun interface Operator<X, Y> {
|
||||
fun call(source: Observable<X>): Observable<Y>
|
||||
}
|
||||
|
||||
open class Observable<T>(private val subscribeFn: Subscribe<T>) {
|
||||
fun <R> apply(operator: Operator<T, R>): Observable<R> {
|
||||
return operator.call(this)
|
||||
}
|
||||
|
||||
fun subscribe(observer: Observer<T>): Subscription {
|
||||
return Subscription()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun <T> of(vararg elems: T): Observable<T> {
|
||||
return Observable { Subscription() }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user