[FIR] Expand type alias when checking for type parameters from outer declaration

This fixes a false positive OUTER_CLASS_ARGUMENTS_REQUIRED when
referring to an inner class of a supertype that is extended using a
typealias.

#KT-62099 Fixed
This commit is contained in:
Kirill Rakhman
2023-10-24 11:01:17 +02:00
committed by Space Team
parent 907ebb36d0
commit 8821f8d1a4
8 changed files with 74 additions and 4 deletions
@@ -35370,6 +35370,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/typealias/kt57065.kt");
}
@Test
@TestMetadata("kt62099.kt")
public void testKt62099() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/kt62099.kt");
}
@Test
@TestMetadata("localTypeAlias.kt")
public void testLocalTypeAlias() throws Exception {
@@ -35370,6 +35370,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/typealias/kt57065.kt");
}
@Test
@TestMetadata("kt62099.kt")
public void testKt62099() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/kt62099.kt");
}
@Test
@TestMetadata("localTypeAlias.kt")
public void testLocalTypeAlias() throws Exception {
@@ -35256,6 +35256,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/typealias/kt57065.kt");
}
@Test
@TestMetadata("kt62099.kt")
public void testKt62099() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/kt62099.kt");
}
@Test
@TestMetadata("localTypeAlias.kt")
public void testLocalTypeAlias() throws Exception {
@@ -35370,6 +35370,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/typealias/kt57065.kt");
}
@Test
@TestMetadata("kt62099.kt")
public void testKt62099() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/kt62099.kt");
}
@Test
@TestMetadata("localTypeAlias.kt")
public void testLocalTypeAlias() throws Exception {
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.resolve
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.FirTypeAlias
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
@@ -190,3 +191,10 @@ private fun mapTypeAliasArguments(
fun FirTypeAlias.fullyExpandedConeType(useSiteSession: FirSession): ConeClassLikeType? {
return expandedConeType?.fullyExpandedType(useSiteSession)
}
/**
* @see fullyExpandedType
*/
fun FirTypeAlias.fullyExpandedClass(session: FirSession): FirClassLikeDeclaration? {
return fullyExpandedConeType(session)?.toSymbol(session)?.fir
}
@@ -57,10 +57,9 @@ fun isValidTypeParameterFromOuterDeclaration(
return containsTypeParameter(session.symbolProvider.getClassLikeSymbolByClassId(containingClassId)?.fir)
} else if (currentDeclaration is FirClass) {
for (superTypeRef in currentDeclaration.superTypeRefs) {
val superClassFir = superTypeRef.firClassLike(session)
if (superClassFir == null || superClassFir is FirRegularClass && containsTypeParameter(superClassFir)) {
return true
}
val superClassFir = superTypeRef.firClassLike(session) ?: return true
if (superClassFir is FirRegularClass && containsTypeParameter(superClassFir)) return true
if (superClassFir is FirTypeAlias && containsTypeParameter(superClassFir.fullyExpandedClass(session))) return true
}
}
}
@@ -0,0 +1,33 @@
// FIR_IDENTICAL
// ISSUE: KT-62099
abstract class Foo<T> {
inner class Inner
abstract fun render(context: Inner)
}
typealias TA = Foo<String>
class Test : TA() {
override fun render(context: Inner) {}
}
typealias TA2<T> = Foo<T>
class Test2 : TA2<String>() {
override fun render(context: Inner) {}
}
typealias TA3<T> = Foo<T>
typealias TA3_2<T> = TA3<T>
class Test3 : TA3_2<String>() {
override fun render(context: Inner) {}
}
typealias TA4<T> = Foo<T>
typealias TA4_2 = TA4<String>
class Test4 : TA4_2() {
override fun render(context: Inner) {}
}
@@ -37304,6 +37304,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/typealias/kt57065.kt");
}
@Test
@TestMetadata("kt62099.kt")
public void testKt62099() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/kt62099.kt");
}
@Test
@TestMetadata("localTypeAlias.kt")
public void testLocalTypeAlias() throws Exception {