[FIR] KT-56212 Fix compilation exception caused by type parameter chain

- `FirTypeResolverImpl.resolveSymbol` cannot simply assert that a type
  parameter only has a single qualifier, because code may be fed to the
  compiler where a type parameter is the start of a type chain (see for
  example the added `typeParameterChainInReturnType` test).
- The fix assumes that any multi-qualifier type parameter trivially
  resolves to `null`, because such a chained type cannot exist.

^KT-56212 fixed
^KTIJ-24083 fixed
This commit is contained in:
Marco Pennekamp
2023-01-26 14:08:13 +01:00
committed by Space Team
parent 70ace38788
commit d8671422b1
11 changed files with 63 additions and 4 deletions
@@ -33086,6 +33086,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
}
@Test
@TestMetadata("typeParameterChainInReceiver.kt")
public void testTypeParameterChainInReceiver() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReceiver.kt");
}
@Test
@TestMetadata("typeParameterChainInReturnType.kt")
public void testTypeParameterChainInReturnType() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReturnType.kt");
}
@Test
@TestMetadata("upperBoundCannotBeArray.kt")
public void testUpperBoundCannotBeArray() throws Exception {
@@ -33182,6 +33182,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
}
@Test
@TestMetadata("typeParameterChainInReceiver.kt")
public void testTypeParameterChainInReceiver() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReceiver.kt");
}
@Test
@TestMetadata("typeParameterChainInReturnType.kt")
public void testTypeParameterChainInReturnType() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReturnType.kt");
}
@Test
@TestMetadata("upperBoundCannotBeArray.kt")
public void testUpperBoundCannotBeArray() throws Exception {
@@ -33086,6 +33086,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
}
@Test
@TestMetadata("typeParameterChainInReceiver.kt")
public void testTypeParameterChainInReceiver() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReceiver.kt");
}
@Test
@TestMetadata("typeParameterChainInReturnType.kt")
public void testTypeParameterChainInReturnType() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReturnType.kt");
}
@Test
@TestMetadata("upperBoundCannotBeArray.kt")
public void testUpperBoundCannotBeArray() throws Exception {
@@ -73,10 +73,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
?: qualifierResolver.resolveEnumEntrySymbol(qualifier, symbol.classId)
}
}
is FirTypeParameterSymbol -> {
assert(qualifier.size == 1)
symbol
}
is FirTypeParameterSymbol -> symbol.takeIf { qualifier.size == 1 }
else -> error("!")
}
}
@@ -0,0 +1,2 @@
// ISSUE: KT-56212
fun <F> <!UNRESOLVED_REFERENCE!>F.X<!>.f(): Boolean = false
@@ -0,0 +1,2 @@
// ISSUE: KT-56212
fun <F> F.<!UNRESOLVED_REFERENCE!>X<!>.f(): Boolean = false
@@ -0,0 +1,3 @@
package
public fun </*0*/ F> [Error type: Unresolved type for F.X].f(): kotlin.Boolean
@@ -0,0 +1,2 @@
// ISSUE: KT-56212
fun <F> foo(): <!UNRESOLVED_REFERENCE!>F.X<!> = TODO()
@@ -0,0 +1,2 @@
// ISSUE: KT-56212
fun <F> foo(): F.<!UNRESOLVED_REFERENCE!>X<!> = TODO()
@@ -0,0 +1,3 @@
package
public fun </*0*/ F> foo(): [Error type: Unresolved type for F.X]
@@ -33182,6 +33182,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeMismatchErrorHasExpectedGenericTypeArgumentInsteadOfTypeParameter.kt");
}
@Test
@TestMetadata("typeParameterChainInReceiver.kt")
public void testTypeParameterChainInReceiver() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReceiver.kt");
}
@Test
@TestMetadata("typeParameterChainInReturnType.kt")
public void testTypeParameterChainInReturnType() throws Exception {
runTest("compiler/testData/diagnostics/tests/typeParameters/typeParameterChainInReturnType.kt");
}
@Test
@TestMetadata("upperBoundCannotBeArray.kt")
public void testUpperBoundCannotBeArray() throws Exception {