[UAST] Fix mapping types containing type aliases

#KT-27935 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-04-03 20:08:23 +03:00
parent 73e1ddc505
commit 86fd4da567
15 changed files with 106 additions and 13 deletions
@@ -200,7 +200,8 @@ class KotlinTypeMapper @JvmOverloads constructor(
return mapType(returnType, sw, TypeMappingMode.getModeForReturnTypeNoGeneric(isAnnotationMethod))
}
val typeMappingModeFromAnnotation = extractTypeMappingModeFromAnnotation(descriptor, returnType, isAnnotationMethod)
val typeMappingModeFromAnnotation =
extractTypeMappingModeFromAnnotation(descriptor, returnType, isAnnotationMethod, mapTypeAliases = false)
if (typeMappingModeFromAnnotation != null) {
return mapType(returnType, sw, typeMappingModeFromAnnotation)
}
@@ -1020,7 +1021,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
}
val typeMappingMode =
extractTypeMappingModeFromAnnotation(callableDescriptor, type, isForAnnotationParameter = false)
extractTypeMappingModeFromAnnotation(callableDescriptor, type, isForAnnotationParameter = false, mapTypeAliases = false)
?: if (callableDescriptor.isMethodWithDeclarationSiteWildcards && type.arguments.isNotEmpty()) {
TypeMappingMode.GENERIC_ARGUMENT // Render all wildcards
} else {
@@ -93,7 +93,8 @@ fun TypeMappingMode.updateArgumentModeFromAnnotations(
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
skipDeclarationSiteWildcards = it,
isForAnnotationParameter = isForAnnotationParameter,
needInlineClassWrapping = needInlineClassWrapping
needInlineClassWrapping = needInlineClassWrapping,
mapTypeAliases = mapTypeAliases
)
}
@@ -102,7 +103,8 @@ fun TypeMappingMode.updateArgumentModeFromAnnotations(
skipDeclarationSiteWildcards = false,
isForAnnotationParameter = isForAnnotationParameter,
fallbackMode = this,
needInlineClassWrapping = needInlineClassWrapping
needInlineClassWrapping = needInlineClassWrapping,
mapTypeAliases = mapTypeAliases
)
}
@@ -112,16 +114,18 @@ fun TypeMappingMode.updateArgumentModeFromAnnotations(
internal fun extractTypeMappingModeFromAnnotation(
callableDescriptor: CallableDescriptor?,
outerType: KotlinType,
isForAnnotationParameter: Boolean
isForAnnotationParameter: Boolean,
mapTypeAliases: Boolean
): TypeMappingMode? =
SimpleClassicTypeSystemContext.extractTypeMappingModeFromAnnotation(
callableDescriptor?.suppressWildcardsMode(), outerType, isForAnnotationParameter
callableDescriptor?.suppressWildcardsMode(), outerType, isForAnnotationParameter, mapTypeAliases
)
fun TypeSystemCommonBackendContext.extractTypeMappingModeFromAnnotation(
callableSuppressWildcardsMode: Boolean?,
outerType: KotlinTypeMarker,
isForAnnotationParameter: Boolean
isForAnnotationParameter: Boolean,
mapTypeAliases: Boolean
): TypeMappingMode? {
val suppressWildcards =
outerType.suppressWildcardsMode(this) ?: callableSuppressWildcardsMode ?: return null
@@ -131,7 +135,8 @@ fun TypeSystemCommonBackendContext.extractTypeMappingModeFromAnnotation(
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
skipDeclarationSiteWildcards = suppressWildcards,
isForAnnotationParameter = isForAnnotationParameter,
needInlineClassWrapping = !outerType.typeConstructor().isInlineClass()
needInlineClassWrapping = !outerType.typeConstructor().isInlineClass(),
mapTypeAliases = mapTypeAliases
)
}
@@ -24028,6 +24028,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.kt");
}
@TestMetadata("typeAliasIsUsedAsATypeArgumentInOtherAlias.kt")
public void testTypeAliasIsUsedAsATypeArgumentInOtherAlias() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasIsUsedAsATypeArgumentInOtherAlias.kt");
}
@TestMetadata("typeAliasNotNull.kt")
public void testTypeAliasNotNull() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.kt");
@@ -159,7 +159,9 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
}
val typeMappingModeFromAnnotation =
typeSystem.extractTypeMappingModeFromAnnotation(declaration.suppressWildcardsMode(), returnType, isAnnotationMethod)
typeSystem.extractTypeMappingModeFromAnnotation(
declaration.suppressWildcardsMode(), returnType, isAnnotationMethod, mapTypeAliases = false
)
if (typeMappingModeFromAnnotation != null) {
return typeMapper.mapType(returnType, typeMappingModeFromAnnotation, sw)
}
@@ -259,7 +261,9 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
}
val mode = with(typeSystem) {
extractTypeMappingModeFromAnnotation(declaration.suppressWildcardsMode(), type, isForAnnotationParameter = false)
extractTypeMappingModeFromAnnotation(
declaration.suppressWildcardsMode(), type, isForAnnotationParameter = false, mapTypeAliases = false
)
?: if (declaration.isMethodWithDeclarationSiteWildcards && type.argumentsCount() != 0) {
TypeMappingMode.GENERIC_ARGUMENT // Render all wildcards
} else {
@@ -0,0 +1,4 @@
// FIR_IDENTICAL
typealias A = String
typealias My = (Map<A, Int>) -> Unit
@@ -0,0 +1,4 @@
package
public typealias A = kotlin.String
public typealias My = (kotlin.collections.Map<A, kotlin.Int>) -> kotlin.Unit
@@ -24110,6 +24110,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.kt");
}
@TestMetadata("typeAliasIsUsedAsATypeArgumentInOtherAlias.kt")
public void testTypeAliasIsUsedAsATypeArgumentInOtherAlias() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasIsUsedAsATypeArgumentInOtherAlias.kt");
}
@TestMetadata("typeAliasNotNull.kt")
public void testTypeAliasNotNull() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.kt");
@@ -24030,6 +24030,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.kt");
}
@TestMetadata("typeAliasIsUsedAsATypeArgumentInOtherAlias.kt")
public void testTypeAliasIsUsedAsATypeArgumentInOtherAlias() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasIsUsedAsATypeArgumentInOtherAlias.kt");
}
@TestMetadata("typeAliasNotNull.kt")
public void testTypeAliasNotNull() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.kt");