[NI] Fix passing callable references to suspend functions as functional parameter
#KT-32452
This commit is contained in:
+10
@@ -1722,6 +1722,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt31981.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32256.kt")
|
||||
public void testKt32256() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt32256.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt7430_wrongClassOnLHS.kt")
|
||||
public void testKt7430_wrongClassOnLHS() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt");
|
||||
@@ -1767,6 +1772,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/subtypeArgumentFromRHSForReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendCallableReference.kt")
|
||||
public void testSuspendCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/suspendCallableReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typealiases.kt")
|
||||
public void testTypealiases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/typealiases.kt");
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// Issue: KT-32256
|
||||
|
||||
fun main() {
|
||||
myMethod(::refA)
|
||||
myMethod(::refB)
|
||||
anotherMethod(::refA)
|
||||
anotherMethod(::refB)
|
||||
}
|
||||
|
||||
suspend fun refA(input: String): String {
|
||||
return input
|
||||
}
|
||||
|
||||
suspend fun refB(): String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
|
||||
fun myMethod(f: suspend (String) -> String) {}
|
||||
|
||||
fun myMethod(f: suspend () -> String) {}
|
||||
|
||||
fun <I, O> anotherMethod(f: suspend (I) -> O) {}
|
||||
|
||||
fun <O> anotherMethod(f: suspend () -> O) {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ O> anotherMethod(/*0*/ f: suspend () -> O): kotlin.Unit
|
||||
public fun </*0*/ I, /*1*/ O> anotherMethod(/*0*/ f: suspend (I) -> O): kotlin.Unit
|
||||
public fun main(): kotlin.Unit
|
||||
public fun myMethod(/*0*/ f: suspend () -> kotlin.String): kotlin.Unit
|
||||
public fun myMethod(/*0*/ f: suspend (kotlin.String) -> kotlin.String): kotlin.Unit
|
||||
public suspend fun refA(/*0*/ input: kotlin.String): kotlin.String
|
||||
public suspend fun refB(): kotlin.String
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// ISSUE: KT-32452
|
||||
|
||||
interface A {
|
||||
suspend fun foo(input: String): String
|
||||
}
|
||||
|
||||
open class B<T : Any> {
|
||||
fun <U, R : Any, T> call(function: suspend T.(U) -> R): R = TODO()
|
||||
|
||||
fun <U, R : Any, T> call(function: suspend T.(U) -> List<R>): List<R> = TODO()
|
||||
}
|
||||
|
||||
class MyService : A, B<A>() {
|
||||
override suspend fun foo(input: String) = call(A::foo)
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package
|
||||
|
||||
public interface A {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract suspend fun foo(/*0*/ input: kotlin.String): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class B</*0*/ T : kotlin.Any> {
|
||||
public constructor B</*0*/ T : kotlin.Any>()
|
||||
public final fun </*0*/ U, /*1*/ R : kotlin.Any, /*2*/ T> call(/*0*/ function: suspend T.(U) -> R): R
|
||||
public final fun </*0*/ U, /*1*/ R : kotlin.Any, /*2*/ T> call(/*0*/ function: suspend T.(U) -> kotlin.collections.List<R>): kotlin.collections.List<R>
|
||||
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class MyService : A, B<A> {
|
||||
public constructor MyService()
|
||||
public final override /*1*/ /*fake_override*/ fun </*0*/ U, /*1*/ R : kotlin.Any, /*2*/ T> call(/*0*/ function: suspend T.(U) -> R): R
|
||||
public final override /*1*/ /*fake_override*/ fun </*0*/ U, /*1*/ R : kotlin.Any, /*2*/ T> call(/*0*/ function: suspend T.(U) -> kotlin.collections.List<R>): kotlin.collections.List<R>
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ suspend fun foo(/*0*/ input: kotlin.String): kotlin.String
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -1729,6 +1729,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt31981.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32256.kt")
|
||||
public void testKt32256() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt32256.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt7430_wrongClassOnLHS.kt")
|
||||
public void testKt7430_wrongClassOnLHS() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt");
|
||||
@@ -1774,6 +1779,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/subtypeArgumentFromRHSForReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendCallableReference.kt")
|
||||
public void testSuspendCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/suspendCallableReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typealiases.kt")
|
||||
public void testTypealiases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/typealiases.kt");
|
||||
|
||||
Generated
+10
@@ -1724,6 +1724,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt31981.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32256.kt")
|
||||
public void testKt32256() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt32256.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt7430_wrongClassOnLHS.kt")
|
||||
public void testKt7430_wrongClassOnLHS() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt");
|
||||
@@ -1769,6 +1774,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/subtypeArgumentFromRHSForReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendCallableReference.kt")
|
||||
public void testSuspendCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/suspendCallableReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typealiases.kt")
|
||||
public void testTypealiases() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/typealiases.kt");
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import kotlin.reflect.KProperty
|
||||
@@ -206,7 +207,7 @@ class ReflectionTypes(module: ModuleDescriptor, private val notFoundClasses: Not
|
||||
|| shortName == "KCallable" || shortName == "KAnnotatedElement"
|
||||
|
||||
}
|
||||
if (packageName == KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) {
|
||||
if (packageName == KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME || packageName == COROUTINES_PACKAGE_FQ_NAME_RELEASE) {
|
||||
return shortName.startsWith("Function") // FunctionN, Function
|
||||
|| shortName.startsWith("SuspendFunction")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user