Fix serialization of type parameters inner generic class
The call to `createTopLevel` instead of `create` (which creates
serializers for outer classes properly, with correct type parameter
contexts) caused MetadataSerializer to write type parameter metadata
incorrectly. For example, in the following case:
class A<E> {
inner class B<T, E> { ... }
}
A's type parameter E would get id 0, and B's type parameters T and E
would get ids 0 and 1. This is a problem because ids are supposed to be
unique for each class including its outer classes, and deserializer,
decompiler and stub builder rely on this assumption.
JVM metadata is unaffected because `create` is called correctly there,
see MemberCodegen#generateKotlinClassMetadataAnnotation
#KT-24944 Fixed
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
class A<E> {
|
||||
inner class B<T, E> {
|
||||
fun getAE() = this@A.getAE()
|
||||
fun getBT(): T? = null
|
||||
fun getBE(): E? = null
|
||||
}
|
||||
|
||||
fun getAE(): E? = null
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun test(): String {
|
||||
val b = A<String>().B<Int, Double>()
|
||||
val x: String? = b.getAE()
|
||||
val y: Int? = b.getBT()
|
||||
val z: Double? = b.getBE()
|
||||
|
||||
// This line is needed to ensure that B.getAE's return type is not an error type; if it was, this line would compile with no errors
|
||||
b.getAE().unresolved()
|
||||
|
||||
return "$x$y$z"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
-- Common --
|
||||
Exit code: OK
|
||||
Output:
|
||||
|
||||
-- Common (2) --
|
||||
Exit code: COMPILATION_ERROR
|
||||
Output:
|
||||
compiler/testData/multiplatform/innerGenericClass/common2.kt:8:15: error: unresolved reference: unresolved
|
||||
b.getAE().unresolved()
|
||||
^
|
||||
Reference in New Issue
Block a user