[NI] Approximate receivers for callable reference candidates
#KT-36221 Fixed
This commit is contained in:
+4
-2
@@ -369,8 +369,10 @@ class ResolvedAtomCompleter(
|
||||
}
|
||||
|
||||
private fun ReceiverValue.updateReceiverValue(substitutor: TypeSubstitutor): ReceiverValue {
|
||||
val newType = substitutor.safeSubstitute(type, Variance.INVARIANT)
|
||||
return if (type != newType) replaceType(newType) else this
|
||||
val newType = substitutor.safeSubstitute(type, Variance.INVARIANT).let {
|
||||
typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference) ?: it
|
||||
}
|
||||
return if (type != newType) replaceType(newType as KotlinType) else this
|
||||
}
|
||||
|
||||
private fun recordArgumentAdaptationForCallableReference(
|
||||
|
||||
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun <T> bar0(vararg a: T) = test(a::get)
|
||||
fun <T> bar1(vararg a: T) = test(a::set)
|
||||
|
||||
fun <T> bar2(a: Array<out T>) = test(a::get)
|
||||
fun <T> bar3(a: Array<out T>) = test(a::set)
|
||||
|
||||
fun <T> bar4(a: Array<in T>) = test(a::get)
|
||||
fun <T> bar5(a: Array<in T>) = test(a::set)
|
||||
|
||||
fun <F> test(f: F): String = f.toString()
|
||||
|
||||
fun box(): String {
|
||||
val getMethod = "fun kotlin.Array<T>.get(kotlin.Int): T"
|
||||
val setMethod = "fun kotlin.Array<T>.set(kotlin.Int, T): kotlin.Unit"
|
||||
|
||||
val b0 = bar0("")
|
||||
val b1 = bar1("")
|
||||
|
||||
assertEquals(getMethod, b0)
|
||||
assertEquals(setMethod, b1)
|
||||
|
||||
val b2 = bar2(arrayOf(""))
|
||||
val b3 = bar3(arrayOf(""))
|
||||
|
||||
assertEquals(getMethod, b2)
|
||||
assertEquals(setMethod, b3)
|
||||
|
||||
val b4 = bar4(arrayOf(""))
|
||||
val b5 = bar5(arrayOf(""))
|
||||
|
||||
assertEquals(getMethod, b4)
|
||||
assertEquals(setMethod, b5)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -2082,6 +2082,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToGetSetMethodsFromVararg.kt")
|
||||
public void testReferenceToGetSetMethodsFromVararg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/referenceToGetSetMethodsFromVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleFunction.kt")
|
||||
public void testSimpleFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt");
|
||||
|
||||
+5
@@ -2082,6 +2082,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToGetSetMethodsFromVararg.kt")
|
||||
public void testReferenceToGetSetMethodsFromVararg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/referenceToGetSetMethodsFromVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleFunction.kt")
|
||||
public void testSimpleFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt");
|
||||
|
||||
+5
@@ -2062,6 +2062,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToGetSetMethodsFromVararg.kt")
|
||||
public void testReferenceToGetSetMethodsFromVararg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/referenceToGetSetMethodsFromVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleFunction.kt")
|
||||
public void testSimpleFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt");
|
||||
|
||||
+5
@@ -2062,6 +2062,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToGetSetMethodsFromVararg.kt")
|
||||
public void testReferenceToGetSetMethodsFromVararg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/referenceToGetSetMethodsFromVararg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleFunction.kt")
|
||||
public void testSimpleFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user