[AA LC] Expand aliases of type arguments during conversion to KtType

^KT-55781
This commit is contained in:
Dmitriy Novozhilov
2022-10-03 17:01:25 +03:00
committed by Space Team
parent 36ae901b19
commit ed867af01d
10 changed files with 80 additions and 2 deletions
@@ -107,6 +107,9 @@ private fun ConeKotlinType.simplifyType(
?: currentType
} while (oldType !== currentType)
if (typeArguments.isNotEmpty()) {
currentType = currentType.withArguments { it.replaceType(it.type?.simplifyType(session, useSitePosition)) }
}
return currentType
}
@@ -270,6 +270,12 @@ public class SymbolLightClassesByFqNameForLibraryTestGenerated extends AbstractS
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/TypePararametersInClass.kt");
}
@Test
@TestMetadata("typealiasInTypeArguments.kt")
public void testTypealiasInTypeArguments() throws Exception {
runTest("compiler/testData/asJava/lightClasses/typealiasInTypeArguments.kt");
}
@Test
@TestMetadata("VarArgs.kt")
public void testVarArgs() throws Exception {
@@ -270,6 +270,12 @@ public class SymbolLightClassesParentingForLibraryTestGenerated extends Abstract
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/TypePararametersInClass.kt");
}
@Test
@TestMetadata("typealiasInTypeArguments.kt")
public void testTypealiasInTypeArguments() throws Exception {
runTest("compiler/testData/asJava/lightClasses/typealiasInTypeArguments.kt");
}
@Test
@TestMetadata("VarArgs.kt")
public void testVarArgs() throws Exception {
@@ -270,6 +270,12 @@ public class SymbolLightClassesByFqNameForSourceTestGenerated extends AbstractSy
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/TypePararametersInClass.kt");
}
@Test
@TestMetadata("typealiasInTypeArguments.kt")
public void testTypealiasInTypeArguments() throws Exception {
runTest("compiler/testData/asJava/lightClasses/typealiasInTypeArguments.kt");
}
@Test
@TestMetadata("VarArgs.kt")
public void testVarArgs() throws Exception {
@@ -270,6 +270,12 @@ public class SymbolLightClassesParentingForSourceTestGenerated extends AbstractS
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/TypePararametersInClass.kt");
}
@Test
@TestMetadata("typealiasInTypeArguments.kt")
public void testTypealiasInTypeArguments() throws Exception {
runTest("compiler/testData/asJava/lightClasses/typealiasInTypeArguments.kt");
}
@Test
@TestMetadata("VarArgs.kt")
public void testVarArgs() throws Exception {
@@ -61,8 +61,26 @@ val ConeTypeProjection.type: ConeKotlinType?
get() = when (this) {
ConeStarProjection -> null
is ConeKotlinTypeProjection -> type
is ConeKotlinType -> this
}
val ConeTypeProjection.isStarProjection: Boolean
get() = this == ConeStarProjection
fun ConeTypeProjection.replaceType(newType: ConeKotlinType?): ConeTypeProjection {
return when (this) {
is ConeStarProjection -> this
is ConeKotlinTypeProjection -> {
requireNotNull(newType) { "Type for non star projection should be not null" }
replaceType(newType)
}
}
}
fun ConeKotlinTypeProjection.replaceType(newType: ConeKotlinType): ConeKotlinTypeProjection {
return when (this) {
is ConeKotlinType -> newType
is ConeKotlinTypeProjectionIn -> ConeKotlinTypeProjectionIn(newType)
is ConeKotlinTypeProjectionOut -> ConeKotlinTypeProjectionOut(newType)
is ConeKotlinTypeConflictingProjection -> ConeKotlinTypeConflictingProjection(newType)
}
}
@@ -119,7 +119,7 @@ fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection
@Suppress("UNCHECKED_CAST")
return when (this) {
is ConeErrorType -> ConeErrorType(diagnostic, isUninferredParameter, arguments, attributes) as T
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable) as T
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable, attributes) as T
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments)) as T
else -> error("Not supported: $this: ${this.renderForDebugging()}")
}
@@ -0,0 +1,13 @@
public abstract interface Test /* Test*/ {
@org.jetbrains.annotations.NotNull()
public abstract A foo();// foo()
@org.jetbrains.annotations.NotNull()
public abstract A fooAliased();// fooAliased()
@org.jetbrains.annotations.NotNull()
public abstract B<A, B<A, java.lang.String>> bar();// bar()
@org.jetbrains.annotations.NotNull()
public abstract B<A, B<A, java.lang.String>> barAliased();// barAliased()
}
@@ -0,0 +1,15 @@
// Test
interface A
interface B<T, R>
typealias OtherA = A
typealias OtherOtherA = OtherA
typealias OtherB<X, Y> = B<Y, X>
interface Test {
fun foo(): A
fun fooAliased(): OtherA
fun bar(): B<A, B<A, String>>
fun barAliased(): OtherB<OtherB<String, OtherA>, OtherOtherA>
}
@@ -234,6 +234,11 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/TypePararametersInClass.kt");
}
@TestMetadata("typealiasInTypeArguments.kt")
public void testTypealiasInTypeArguments() throws Exception {
runTest("compiler/testData/asJava/lightClasses/typealiasInTypeArguments.kt");
}
@TestMetadata("VarArgs.kt")
public void testVarArgs() throws Exception {
runTest("compiler/testData/asJava/lightClasses/lightClassByFqName/VarArgs.kt");