[FIR] Resolve LHS of type operator call in independent context

#KT-39046 Fixed
This commit is contained in:
Dmitriy Novozhilov
2020-06-30 12:13:53 +03:00
parent c9e423bf64
commit 624b9306f0
10 changed files with 59 additions and 6 deletions
@@ -0,0 +1,17 @@
// ISSUE: KT-39046
fun foo(b: B<Int, Int>) {}
fun test_1(b: B<String, Number>) {
foo(b.myMap {
it.k.length // implicits
} as B<Int, Int>)
}
fun test_2(s: String) {
val func = { s.length } as B<Int, Int>
}
class B<out K, V>(val k: K, val v: V)
fun <X, R, V> B<X, V>.myMap(transform: (B<X, V>) -> R): B<R, V> = TODO()
@@ -0,0 +1,30 @@
FILE: lambdaInLhsOfTypeOperatorCall.kt
public final fun foo(b: R|B<kotlin/Int, kotlin/Int>|): R|kotlin/Unit| {
}
public final fun test_1(b: R|B<kotlin/String, kotlin/Number>|): R|kotlin/Unit| {
R|/foo|((R|<local>/b|.R|/myMap|<R|kotlin/String|, R|kotlin/Int|, R|kotlin/Number|>(<L> = myMap@fun <anonymous>(it: R|B<kotlin/String, kotlin/Number>|): R|kotlin/Int| {
^ R|<local>/it|.R|FakeOverride</B.k: R|kotlin/String|>|.R|kotlin/String.length|
}
) as R|B<kotlin/Int, kotlin/Int>|))
}
public final fun test_2(s: R|kotlin/String|): R|kotlin/Unit| {
lval func: R|B<kotlin/Int, kotlin/Int>| = (fun <anonymous>(): R|kotlin/Int| {
^ R|<local>/s|.R|kotlin/String.length|
}
as R|B<kotlin/Int, kotlin/Int>|)
}
public final class B<out K, V> : R|kotlin/Any| {
public constructor<out K, V>(k: R|K|, v: R|V|): R|B<K, V>| {
super<R|kotlin/Any|>()
}
public final val k: R|K| = R|<local>/k|
public get(): R|K|
public final val v: R|V| = R|<local>/v|
public get(): R|V|
}
public final fun <X, R, V> R|B<X, V>|.myMap(transform: R|(B<X, V>) -> R|): R|B<R, V>| {
^myMap R|kotlin/TODO|()
}
@@ -243,6 +243,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/lambdaArgInScopeFunction.kt");
}
@TestMetadata("lambdaInLhsOfTypeOperatorCall.kt")
public void testLambdaInLhsOfTypeOperatorCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/lambdaInLhsOfTypeOperatorCall.kt");
}
@TestMetadata("lambdaPropertyTypeInference.kt")
public void testLambdaPropertyTypeInference() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/lambdaPropertyTypeInference.kt");
@@ -243,6 +243,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/lambdaArgInScopeFunction.kt");
}
@TestMetadata("lambdaInLhsOfTypeOperatorCall.kt")
public void testLambdaInLhsOfTypeOperatorCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/lambdaInLhsOfTypeOperatorCall.kt");
}
@TestMetadata("lambdaPropertyTypeInference.kt")
public void testLambdaPropertyTypeInference() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/lambdaPropertyTypeInference.kt");
@@ -385,7 +385,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
typeOperatorCall: FirTypeOperatorCall,
data: ResolutionMode,
): CompositeTransformResult<FirStatement> {
val resolved = transformExpression(typeOperatorCall, data).single as FirTypeOperatorCall
val resolved = transformExpression(typeOperatorCall, ResolutionMode.ContextIndependent).single as FirTypeOperatorCall
resolved.argumentList.transformArguments(integerLiteralTypeApproximator, null)
val conversionTypeRef = resolved.conversionTypeRef.withTypeArgumentsForBareType(resolved.argument)
resolved.transformChildren(object : FirDefaultTransformer<Nothing?>() {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
import kotlin.test.assertEquals
@@ -1,5 +1,4 @@
// !LANGUAGE: +FunctionTypesWithBigArity
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: Test.java
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_REFLECT
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
import kotlin.reflect.*
@@ -7,4 +7,4 @@ fun bar(f: () -> Unit) = 1
fun bar(f: (String) -> Unit) = 2
val x1 = <!UNRESOLVED_REFERENCE!>::foo<!> as () -> Unit
val x2 = bar(::foo as (String) -> Unit)
val x2 = bar(<!UNRESOLVED_REFERENCE!>::foo<!> as (String) -> Unit)