FIR: perform type approximation when completion isn't required

This commit is contained in:
Mikhail Glukhikh
2020-09-17 18:03:21 +03:00
parent 0310272738
commit b7059a3eeb
4 changed files with 13 additions and 6 deletions
@@ -74,12 +74,12 @@ typealias Invariant1<X> = Invariant<X>
fun test_5(a: A, in1: In1<A>, in2: In1<in A>, in3: In1<out A>) {
in1.take(a)
in2.take(a)
in3.<!INAPPLICABLE_CANDIDATE!>take<!>(a)
in3.<!UNRESOLVED_REFERENCE!>take<!>(a)
}
fun test_6(a: A, out1: Out1<A>, out2: Out1<in A>, out3: Out1<out A>) {
out1.value().foo()
out2.value().<!UNRESOLVED_REFERENCE!>foo<!>()
out2.<!UNRESOLVED_REFERENCE!>value<!>().<!UNRESOLVED_REFERENCE!>foo<!>()
out3.value().foo()
}
@@ -68,11 +68,11 @@ FILE: typeAliasWithTypeArguments.kt
public final fun test_5(a: R|A|, in1: R|In1<A>|, in2: R|In1<in A>|, in3: R|In1<out A>|): R|kotlin/Unit| {
R|<local>/in1|.R|FakeOverride</In.take: R|kotlin/Unit|>|(R|<local>/a|)
R|<local>/in2|.R|FakeOverride</In.take: R|kotlin/Unit|>|(R|<local>/a|)
R|<local>/in3|.<Inapplicable(INAPPLICABLE): /In.take>#(R|<local>/a|)
R|<local>/in3|.<Unresolved name: take>#(R|<local>/a|)
}
public final fun test_6(a: R|A|, out1: R|Out1<A>|, out2: R|Out1<in A>|, out3: R|Out1<out A>|): R|kotlin/Unit| {
R|<local>/out1|.R|FakeOverride</Out.value: R|A|>|().R|/A.foo|()
R|<local>/out2|.R|FakeOverride</Out.value: R|kotlin/Any?|>|().<Unresolved name: foo>#()
R|<local>/out2|.<Unresolved name: value>#().<Unresolved name: foo>#()
R|<local>/out3|.R|FakeOverride</Out.value: R|A|>|().R|/A.foo|()
}
public final fun test_7(a: R|A|, inv1: R|Invariant1<A>|, inv2: R|Invariant1<in A>|, inv3: R|Invariant1<out A>|): R|kotlin/Unit| {
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.calls.*
import org.jetbrains.kotlin.fir.resolve.diagnostics.*
import org.jetbrains.kotlin.fir.resolve.inference.FirStubInferenceSession
import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents
import org.jetbrains.kotlin.fir.resolve.transformers.InvocationKindTransformer
import org.jetbrains.kotlin.fir.resolve.transformers.StoreReceiver
import org.jetbrains.kotlin.fir.resolve.transformers.firClassLike
@@ -35,6 +36,7 @@ import org.jetbrains.kotlin.fir.visitors.*
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) : FirPartialBodyResolveTransformer(transformer) {
private inline val builtinTypes: BuiltinTypes get() = session.builtinTypes
@@ -939,6 +941,11 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
// ------------------------------------------------------------------------------------------------
internal fun <T> storeTypeFromCallee(access: T) where T : FirQualifiedAccess, T : FirExpression {
access.resultType = components.typeFromCallee(access)
val typeFromCallee = components.typeFromCallee(access)
access.resultType = typeFromCallee.withReplacedConeType(
session.inferenceComponents.approximator.approximateToSuperType(
typeFromCallee.type, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
) as ConeKotlinType?
)
}
}
@@ -7,5 +7,5 @@ class In<in T>() {
fun test1(x: In<String>): Unit = x.f("1")
fun test2(x: In<in String>): Unit = x.f("1")
fun test3(x: <!CONFLICTING_PROJECTION!>In<out String><!>): Unit = x.<!NONE_APPLICABLE!>f<!>("1")
fun test3(x: <!CONFLICTING_PROJECTION!>In<out String><!>): Unit = x.<!UNRESOLVED_REFERENCE!>f<!>("1")
fun test4(x: In<*>): Unit = x.<!NONE_APPLICABLE!>f<!>("1")