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:
committed by
Mikhail Glukhikh
parent
89577543a2
commit
73576c80e4
+6
-2
@@ -1168,8 +1168,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
|
|
||||||
fun getIrFieldSymbol(firFieldSymbol: FirFieldSymbol): IrSymbol {
|
fun getIrFieldSymbol(firFieldSymbol: FirFieldSymbol): IrSymbol {
|
||||||
val fir = firFieldSymbol.fir
|
val fir = firFieldSymbol.fir
|
||||||
val irProperty = fieldCache[fir] ?: createIrField(fir).apply {
|
val irProperty = fieldCache[fir] ?: run {
|
||||||
setAndModifyParent(findIrParent(fir))
|
// In case of type parameters from the parent as the field's return type, find the parent ahead to cache type parameters.
|
||||||
|
val irParent = findIrParent(fir)
|
||||||
|
createIrField(fir).apply {
|
||||||
|
setAndModifyParent(irParent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return irProperty.symbol
|
return irProperty.symbol
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -1873,6 +1873,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeParameterFromJavaClass.kt")
|
||||||
|
public void testTypeParameterFromJavaClass() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/firProblems/typeParameterFromJavaClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("typeVariableAfterBuildMap.kt")
|
@TestMetadata("typeVariableAfterBuildMap.kt")
|
||||||
public void testTypeVariableAfterBuildMap() throws Exception {
|
public void testTypeVariableAfterBuildMap() throws Exception {
|
||||||
runTest("compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.kt");
|
runTest("compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.kt");
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1872,6 +1872,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
|||||||
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
runTest("compiler/testData/ir/irText/firProblems/throwableStackTrace.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeParameterFromJavaClass.kt")
|
||||||
|
public void testTypeParameterFromJavaClass() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/firProblems/typeParameterFromJavaClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("typeVariableAfterBuildMap.kt")
|
@TestMetadata("typeVariableAfterBuildMap.kt")
|
||||||
public void testTypeVariableAfterBuildMap() throws Exception {
|
public void testTypeVariableAfterBuildMap() throws Exception {
|
||||||
runTest("compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.kt");
|
runTest("compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user