[NI] Approximate receivers for callable reference candidates

#KT-36221 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-01-31 15:13:14 +03:00
parent 517688e163
commit 60a2d0f037
6 changed files with 66 additions and 2 deletions
@@ -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(
@@ -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"
}
@@ -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");
@@ -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");
@@ -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");
@@ -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");