IR: Fix StackOverflowError caused by using DNN type in lambda

^KT-54140 Fixed
This commit is contained in:
Denis.Zharkov
2023-02-02 13:02:45 +01:00
committed by Space Team
parent c586d7a03a
commit 6d7096b5e9
14 changed files with 92 additions and 4 deletions
@@ -46581,6 +46581,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
}
@Test
@TestMetadata("recursiveDnnTypeInLambda.kt")
public void testRecursiveDnnTypeInLambda() throws Exception {
runTest("compiler/testData/codegen/box/regressions/recursiveDnnTypeInLambda.kt");
}
@Test
@TestMetadata("referenceToSelfInLocal.kt")
public void testReferenceToSelfInLocal() throws Exception {
@@ -1150,7 +1150,9 @@ fun IrType.toIrBasedKotlinType(): KotlinType = when (this) {
is IrSimpleType ->
makeKotlinType(classifier, arguments, isMarkedNullable()).let {
if (classifier is IrTypeParameterSymbol && nullability == SimpleTypeNullability.DEFINITELY_NOT_NULL) {
DefinitelyNotNullType.makeDefinitelyNotNull(it.unwrap()) ?: it
// avoidCheckingActualTypeNullability = true is necessary because in recursive cases `makesSenseToBeDefinitelyNotNull` triggers
// supertype computation for a type parameter and for which bounds we need to call `toIrBasedKotlinType` again
DefinitelyNotNullType.makeDefinitelyNotNull(it.unwrap(), avoidCheckingActualTypeNullability = true) ?: it
} else {
it
}
@@ -0,0 +1,15 @@
fun <T : In<T & Any>?> foo(
value: T,
range: CR<T & Any>
) = value?.run { toString() } ?: "fail"
interface In<T>
interface CR<D>
class Impl : In<Impl> {
override fun toString(): String = "OK"
}
fun box(): String {
return foo(Impl(), object : CR<Impl> {})
}
@@ -44505,6 +44505,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
}
@Test
@TestMetadata("recursiveDnnTypeInLambda.kt")
public void testRecursiveDnnTypeInLambda() throws Exception {
runTest("compiler/testData/codegen/box/regressions/recursiveDnnTypeInLambda.kt");
}
@Test
@TestMetadata("referenceToSelfInLocal.kt")
public void testReferenceToSelfInLocal() throws Exception {
@@ -46581,6 +46581,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
}
@Test
@TestMetadata("recursiveDnnTypeInLambda.kt")
public void testRecursiveDnnTypeInLambda() throws Exception {
runTest("compiler/testData/codegen/box/regressions/recursiveDnnTypeInLambda.kt");
}
@Test
@TestMetadata("referenceToSelfInLocal.kt")
public void testReferenceToSelfInLocal() throws Exception {
@@ -35869,6 +35869,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/regressions/objectInsideDelegation.kt");
}
@TestMetadata("recursiveDnnTypeInLambda.kt")
public void testRecursiveDnnTypeInLambda() throws Exception {
runTest("compiler/testData/codegen/box/regressions/recursiveDnnTypeInLambda.kt");
}
@TestMetadata("referenceToSelfInLocal.kt")
public void testReferenceToSelfInLocal() throws Exception {
runTest("compiler/testData/codegen/box/regressions/referenceToSelfInLocal.kt");