NI: Fix exception during callable references overload resolution
^KT-35847 Fixed
This commit is contained in:
Generated
+5
@@ -2538,6 +2538,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ambiguityWithBoundExtensionReceiver.kt")
|
||||
public void testAmbiguityWithBoundExtensionReceiver() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ambiguousWithVararg.kt")
|
||||
public void testAmbiguousWithVararg() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguousWithVararg.kt");
|
||||
|
||||
+5
@@ -1886,6 +1886,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt35847.kt")
|
||||
public void testKt35847() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt35847.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4975.kt")
|
||||
public void testKt4975() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt");
|
||||
|
||||
+4
-1
@@ -55,7 +55,10 @@ class CallableReferenceOverloadConflictResolver(
|
||||
) {
|
||||
companion object {
|
||||
private fun createFlatSignature(candidate: CallableReferenceCandidate) =
|
||||
FlatSignature.createFromReflectionType(candidate, candidate.candidate, candidate.numDefaults, candidate.reflectionCandidateType)
|
||||
FlatSignature.createFromReflectionType(
|
||||
candidate, candidate.candidate, candidate.numDefaults, hasBoundExtensionReceiver = candidate.extensionReceiver != null,
|
||||
candidate.reflectionCandidateType
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ class FlatSignature<out T> constructor(
|
||||
origin: T,
|
||||
descriptor: CallableDescriptor,
|
||||
numDefaults: Int,
|
||||
// Reflection type for callable references with bound receiver doesn't contain receiver type
|
||||
hasBoundExtensionReceiver: Boolean,
|
||||
reflectionType: UnwrappedType
|
||||
): FlatSignature<T> {
|
||||
// Note that receiver is taking over descriptor, not reflection type
|
||||
@@ -66,7 +68,9 @@ class FlatSignature<out T> constructor(
|
||||
// Plus, currently, receiver for reflection type is taking from *candidate*, see buildReflectionType, this candidate can
|
||||
// have transient receiver which is not the same in its signature
|
||||
val receiver = descriptor.extensionReceiverParameter?.type
|
||||
val parameters = reflectionType.getValueParameterTypesFromCallableReflectionType(receiver == null).map { it.type }
|
||||
val parameters = reflectionType.getValueParameterTypesFromCallableReflectionType(
|
||||
receiver != null && !hasBoundExtensionReceiver
|
||||
).map { it.type }
|
||||
|
||||
return FlatSignature(
|
||||
origin,
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <R> bar(f: () -> R): R = TODO()
|
||||
|
||||
fun Any.foo() = 1
|
||||
fun A.foo() = ""
|
||||
|
||||
class A {
|
||||
fun main() {
|
||||
bar(<!UNRESOLVED_REFERENCE!>::foo<!>) checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !CHECK_TYPE
|
||||
|
||||
fun <R> bar(f: () -> R): R = TODO()
|
||||
|
||||
fun Any.foo() = 1
|
||||
fun A.foo() = ""
|
||||
|
||||
class A {
|
||||
fun main() {
|
||||
bar(::foo) checkType { _<String>() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
fun <T, R> has(property: KFunction1<T, R>) = null
|
||||
fun <T, R> has(property: KProperty1<T, R>) = null
|
||||
|
||||
fun toInt(s: String) = 10
|
||||
|
||||
object A {
|
||||
fun main() {
|
||||
has(::toInt) // throwing an exception here
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
fun <T, R> has(property: KFunction1<T, R>) = null
|
||||
fun <T, R> has(property: KProperty1<T, R>) = null
|
||||
|
||||
fun toInt(s: String) = 10
|
||||
|
||||
object A {
|
||||
fun main() {
|
||||
has(::toInt) // throwing an exception here
|
||||
}
|
||||
}
|
||||
@@ -2545,6 +2545,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ambiguityWithBoundExtensionReceiver.kt")
|
||||
public void testAmbiguityWithBoundExtensionReceiver() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ambiguousWithVararg.kt")
|
||||
public void testAmbiguousWithVararg() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguousWithVararg.kt");
|
||||
|
||||
+5
@@ -2821,6 +2821,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt35847.kt")
|
||||
public void testKt35847() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt35847.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4975.kt")
|
||||
public void testKt4975() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt");
|
||||
|
||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -2821,6 +2821,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt35847.kt")
|
||||
public void testKt35847() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt35847.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4975.kt")
|
||||
public void testKt4975() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt4975.kt");
|
||||
|
||||
Generated
+5
@@ -2540,6 +2540,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ambiguityWithBoundExtensionReceiver.kt")
|
||||
public void testAmbiguityWithBoundExtensionReceiver() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWithBoundExtensionReceiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ambiguousWithVararg.kt")
|
||||
public void testAmbiguousWithVararg() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/ambiguousWithVararg.kt");
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.util.*
|
||||
|
||||
private fun KotlinType.isTypeOrSubtypeOf(predicate: (KotlinType) -> Boolean): Boolean =
|
||||
@@ -140,10 +139,10 @@ fun KotlinType.getValueParameterTypesFromFunctionType(): List<TypeProjection> {
|
||||
return arguments.subList(first, last)
|
||||
}
|
||||
|
||||
fun KotlinType.getValueParameterTypesFromCallableReflectionType(withReceiver: Boolean): List<TypeProjection> {
|
||||
fun KotlinType.getValueParameterTypesFromCallableReflectionType(isCallableTypeWithExtension: Boolean): List<TypeProjection> {
|
||||
assert(ReflectionTypes.isKCallableType(this)) { "Not a callable reflection type: $this" }
|
||||
val arguments = arguments
|
||||
val first = if (withReceiver) 0 else 1
|
||||
val first = if (isCallableTypeWithExtension) 1 else 0
|
||||
val last = arguments.size - 1
|
||||
assert(first <= last) { "Not an exact function type: $this" }
|
||||
return arguments.subList(first, last)
|
||||
|
||||
Reference in New Issue
Block a user