Fix secondary constructors of generic inline classes
#KT-42649 Fixed.
This commit is contained in:
committed by
GitHub
parent
b7470495f2
commit
9b53cded94
+8
-1
@@ -519,6 +519,13 @@ private val Context.getLoweredInlineClassConstructor: (IrConstructor) -> IrSimpl
|
|||||||
).apply {
|
).apply {
|
||||||
descriptor.bind(this)
|
descriptor.bind(this)
|
||||||
parent = irConstructor.parent
|
parent = irConstructor.parent
|
||||||
valueParameters += irConstructor.valueParameters.map { it.copyTo(this) }
|
|
||||||
|
// Note: technically speaking, this function doesn't have access to class type parameters (since it is "static").
|
||||||
|
// But, technically speaking, otherwise we would have to remap types in the entire IR subtree,
|
||||||
|
// which is an overkill here, because type parameters don't matter at this phase of compilation and later.
|
||||||
|
// So it is just a trick to make [copyTo] happy:
|
||||||
|
val remapTypeMap = irConstructor.constructedClass.typeParameters.associateBy { it }
|
||||||
|
|
||||||
|
valueParameters += irConstructor.valueParameters.map { it.copyTo(this, remapTypeMap = remapTypeMap) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3172,6 +3172,10 @@ task inlineClass_defaultEquals(type: KonanLocalTest) {
|
|||||||
source = "codegen/inlineClass/defaultEquals.kt"
|
source = "codegen/inlineClass/defaultEquals.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task inlineClass_secondaryConstructorWithGenerics(type: KonanLocalTest) {
|
||||||
|
source = "codegen/inlineClass/secondaryConstructorWithGenerics.kt"
|
||||||
|
}
|
||||||
|
|
||||||
task deserialized_inline0(type: KonanLocalTest) {
|
task deserialized_inline0(type: KonanLocalTest) {
|
||||||
source = "serialization/deserialized_inline0.kt"
|
source = "serialization/deserialized_inline0.kt"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package codegen.inlineClass.secondaryConstructorWithGenerics
|
||||||
|
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
// Based on KT-42649.
|
||||||
|
inline class IC<T>(val value: List<T>) {
|
||||||
|
constructor(value: T) : this(listOf(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun runTest() {
|
||||||
|
assertEquals("abc", IC("abc").value.singleOrNull())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user