FIR2IR: calculate IR parent for Java field ahead

so as to cache type parameters from the parent if the field's return
type is one of type parameters.

#KT-44032 Fixed
This commit is contained in:
Jinseong Jeon
2020-12-22 12:31:17 -08:00
committed by Mikhail Glukhikh
parent 89577543a2
commit 73576c80e4
8 changed files with 92 additions and 2 deletions
@@ -0,0 +1,6 @@
fun foo(movedPaths: MutableList<Couple<FilePath>>) {
movedPaths.forEach<Couple<FilePath>>(action = local fun <anonymous>(it: Couple<FilePath>) {
it.#second.getName() /*~> Unit */
}
)
}
@@ -0,0 +1,15 @@
FILE fqName:<root> fileName:/typeParameterFromJavaClass.kt
FUN name:foo visibility:public modality:FINAL <> (movedPaths:kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>>) returnType:kotlin.Unit
VALUE_PARAMETER name:movedPaths index:0 type:kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>>
BLOCK_BODY
CALL 'public final fun forEach <T> (action: kotlin.Function1<T of kotlin.collections.forEach, kotlin.Unit>): kotlin.Unit [inline] declared in kotlin.collections' type=kotlin.Unit origin=null
<T>: <root>.Couple<<root>.FilePath>
$receiver: GET_VAR 'movedPaths: kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>> declared in <root>.foo' type=kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>> origin=null
action: FUN_EXPR type=kotlin.Function1<<root>.Couple<<root>.FilePath>, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:<root>.Couple<<root>.FilePath>) returnType:kotlin.Unit
VALUE_PARAMETER name:it index:0 type:<root>.Couple<<root>.FilePath>
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public abstract fun getName (): kotlin.String? declared in <root>.FilePath' type=kotlin.String? origin=GET_PROPERTY
$this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:second type:B of <root>.Pair? visibility:public [final]' type=<root>.FilePath? origin=GET_PROPERTY
receiver: GET_VAR 'it: <root>.Couple<<root>.FilePath> declared in <root>.foo.<anonymous>' type=<root>.Couple<<root>.FilePath> origin=null
@@ -0,0 +1,33 @@
// FILE: Pair.java
public class Pair<A, B> {
public final A first;
public final B second;
public Pair(A first, B second) {
this.first = first;
this.second = second;
}
}
// FILE: Couple.java
public class Couple<T> extends Pair<T, T> {
public Couple(T first, T second) {
super(first, second);
}
}
// FILE: FilePath.java
public interface FilePath {
String getName();
}
// FILE: typeParameterFromJavaClass.kt
// WITH_RUNTIME
fun foo(movedPaths: MutableList<Couple<FilePath>>) {
movedPaths.forEach { it.second.name }
}
@@ -0,0 +1,6 @@
fun foo(movedPaths: MutableList<Couple<FilePath>>) {
movedPaths.forEach<Couple<FilePath>>(action = local fun <anonymous>(it: Couple<FilePath>) {
itsuper.#second /*!! FilePath */.getName() /*~> Unit */
}
)
}
@@ -0,0 +1,16 @@
FILE fqName:<root> fileName:/typeParameterFromJavaClass.kt
FUN name:foo visibility:public modality:FINAL <> (movedPaths:kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>>) returnType:kotlin.Unit
VALUE_PARAMETER name:movedPaths index:0 type:kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>>
BLOCK_BODY
CALL 'public final fun forEach <T> (action: kotlin.Function1<T of kotlin.collections.forEach, kotlin.Unit>): kotlin.Unit [inline] declared in kotlin.collections' type=kotlin.Unit origin=null
<T>: <root>.Couple<<root>.FilePath>
$receiver: GET_VAR 'movedPaths: kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>> declared in <root>.foo' type=kotlin.collections.MutableList<<root>.Couple<<root>.FilePath>> origin=null
action: FUN_EXPR type=kotlin.Function1<<root>.Couple<<root>.FilePath>, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:<root>.Couple<<root>.FilePath>) returnType:kotlin.Unit
VALUE_PARAMETER name:it index:0 type:<root>.Couple<<root>.FilePath>
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public abstract fun getName (): @[FlexibleNullability] kotlin.String? declared in <root>.FilePath' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY
$this: TYPE_OP type=<root>.FilePath origin=IMPLICIT_NOTNULL typeOperand=<root>.FilePath
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:second type:@[FlexibleNullability] B of <root>.Pair? visibility:public [final]' type=@[FlexibleNullability] <root>.FilePath? origin=GET_PROPERTY
receiver: GET_VAR 'it: <root>.Couple<<root>.FilePath> declared in <root>.foo.<anonymous>' type=<root>.Couple<<root>.FilePath> origin=null