FIR: make deeper recursive type alias expansion check (see KT-37000)

This commit is contained in:
Mikhail Glukhikh
2022-03-10 13:49:54 +03:00
committed by Space
parent c8237cb5e2
commit 6ecc97575d
7 changed files with 39 additions and 3 deletions
@@ -452,6 +452,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveCallOnWhenWithSealedClass.kt");
}
@Test
@TestMetadata("recursiveTypeAlias.kt")
public void testRecursiveTypeAlias() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveTypeAlias.kt");
}
@Test
@TestMetadata("sealedClass.kt")
public void testSealedClass() throws Exception {
@@ -384,6 +384,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveCallOnWhenWithSealedClass.kt");
}
@TestMetadata("recursiveTypeAlias.kt")
public void testRecursiveTypeAlias() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveTypeAlias.kt");
}
@TestMetadata("sealedClass.kt")
public void testSealedClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/sealedClass.kt");
@@ -0,0 +1,4 @@
FILE: recursiveTypeAlias.kt
public abstract interface Something<D, T : R|() -> Something1<D>|> : R|kotlin/Any| {
}
public final typealias Something1<D> = <ERROR TYPE REF: Loop in supertype: /Something1 -> /Something>
@@ -0,0 +1,2 @@
interface Something<D, T : () -> Something1<D>>
typealias Something1<D> = <!RECURSIVE_TYPEALIAS_EXPANSION!>Something<D, () -> Something1<D>><!>
@@ -452,6 +452,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveCallOnWhenWithSealedClass.kt");
}
@Test
@TestMetadata("recursiveTypeAlias.kt")
public void testRecursiveTypeAlias() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveTypeAlias.kt");
}
@Test
@TestMetadata("sealedClass.kt")
public void testSealedClass() throws Exception {
@@ -452,6 +452,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveCallOnWhenWithSealedClass.kt");
}
@Test
@TestMetadata("recursiveTypeAlias.kt")
public void testRecursiveTypeAlias() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/recursiveTypeAlias.kt");
}
@Test
@TestMetadata("sealedClass.kt")
public void testSealedClass() throws Exception {
@@ -590,11 +590,18 @@ class SupertypeComputationSession {
checkIsInLoop(supertypeFir)
if (isTypeAlias) {
for (typeArgument in supertypeRef.type.typeArguments) {
if (typeArgument is ConeClassLikeType) {
checkIsInLoop(typeArgument.lookupTag.toSymbol(session)?.fir)
fun checkTypeArgumentsRecursively(type: ConeKotlinType, visitedTypes: MutableSet<ConeKotlinType>) {
if (type in visitedTypes) return
visitedTypes += type
for (typeArgument in type.typeArguments) {
if (typeArgument is ConeClassLikeType) {
checkIsInLoop(typeArgument.lookupTag.toSymbol(session)?.fir)
checkTypeArgumentsRecursively(typeArgument, visitedTypes)
}
}
}
checkTypeArgumentsRecursively(supertypeRef.type, mutableSetOf())
}
resultSupertypeRefs.add(