Fix typealias usage nullability and annotations lost in deserialization
Issue #KT-40824 Fixed
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_REFLECT
|
||||||
|
// FILE: A.kt
|
||||||
|
@Target(AnnotationTarget.TYPE)
|
||||||
|
annotation class Anno(val value: String)
|
||||||
|
|
||||||
|
class Foo
|
||||||
|
|
||||||
|
typealias MyFoo = Foo
|
||||||
|
typealias MyMaybeFoo = Foo?
|
||||||
|
|
||||||
|
class C<T>(val t: T)
|
||||||
|
|
||||||
|
typealias MyCMyFoo = C<@Anno("OK") MyFoo?>
|
||||||
|
typealias MyCMaybeFoo = C<@Anno("OK") MyMaybeFoo>
|
||||||
|
|
||||||
|
// FILE: B.kt
|
||||||
|
fun testMyFoo(myc: MyCMyFoo) {}
|
||||||
|
fun testMyMaybeFoo(mycmyb: MyCMaybeFoo) {}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testMyFoo(C(null))
|
||||||
|
testMyMaybeFoo(C(null))
|
||||||
|
|
||||||
|
for (fn in listOf(::testMyFoo, ::testMyMaybeFoo)) {
|
||||||
|
val mycType = fn.parameters.single().type
|
||||||
|
val argumentType = mycType.arguments.single().type!!
|
||||||
|
if (!argumentType.isMarkedNullable)
|
||||||
|
return "Fail on $fn: argument type should be seen as nullable"
|
||||||
|
|
||||||
|
val annotations = argumentType.annotations
|
||||||
|
if (annotations.toString() != "[@Anno(value=OK)]")
|
||||||
|
return "Fail on $fn: $annotations"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+5
@@ -38,6 +38,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
|
|||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationInInterface.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationInInterface.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("annotationOnTypeUseInTypeAlias.kt")
|
||||||
|
public void testAnnotationOnTypeUseInTypeAlias() throws Exception {
|
||||||
|
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationOnTypeUseInTypeAlias.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("annotationsOnTypeAliases.kt")
|
@TestMetadata("annotationsOnTypeAliases.kt")
|
||||||
public void testAnnotationsOnTypeAliases() throws Exception {
|
public void testAnnotationsOnTypeAliases() throws Exception {
|
||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt");
|
||||||
|
|||||||
Generated
+5
@@ -38,6 +38,11 @@ public class IrCompileKotlinAgainstKotlinTestGenerated extends AbstractIrCompile
|
|||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationInInterface.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationInInterface.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("annotationOnTypeUseInTypeAlias.kt")
|
||||||
|
public void testAnnotationOnTypeUseInTypeAlias() throws Exception {
|
||||||
|
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationOnTypeUseInTypeAlias.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("annotationsOnTypeAliases.kt")
|
@TestMetadata("annotationsOnTypeAliases.kt")
|
||||||
public void testAnnotationsOnTypeAliases() throws Exception {
|
public void testAnnotationsOnTypeAliases() throws Exception {
|
||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/annotationsOnTypeAliases.kt");
|
||||||
|
|||||||
+6
-2
@@ -92,8 +92,12 @@ class TypeDeserializer(
|
|||||||
val declarationDescriptor = constructor.declarationDescriptor
|
val declarationDescriptor = constructor.declarationDescriptor
|
||||||
|
|
||||||
val simpleType = when {
|
val simpleType = when {
|
||||||
expandTypeAliases && declarationDescriptor is TypeAliasDescriptor ->
|
expandTypeAliases && declarationDescriptor is TypeAliasDescriptor -> {
|
||||||
with(KotlinTypeFactory) { declarationDescriptor.computeExpandedType(arguments) }
|
val expandedType = with(KotlinTypeFactory) { declarationDescriptor.computeExpandedType(arguments) }
|
||||||
|
expandedType
|
||||||
|
.makeNullableAsSpecified(expandedType.isNullable() || proto.nullable)
|
||||||
|
.replaceAnnotations(Annotations.create(annotations + expandedType.annotations))
|
||||||
|
}
|
||||||
Flags.SUSPEND_TYPE.get(proto.flags) ->
|
Flags.SUSPEND_TYPE.get(proto.flags) ->
|
||||||
createSuspendFunctionType(annotations, constructor, arguments, proto.nullable)
|
createSuspendFunctionType(annotations, constructor, arguments, proto.nullable)
|
||||||
else ->
|
else ->
|
||||||
|
|||||||
Reference in New Issue
Block a user