[K/N][IR] Ref to expect property in actual declaration is not remapped
^KT-36880
This commit is contained in:
+12
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.backend.konan.ir
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||||
@@ -25,9 +26,15 @@ class ModuleIndex(val module: IrModuleFragment) {
|
|||||||
*/
|
*/
|
||||||
val functions: Map<FunctionDescriptor, IrFunction>
|
val functions: Map<FunctionDescriptor, IrFunction>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains all properties declared in [module]
|
||||||
|
*/
|
||||||
|
val properties: Map<PropertyDescriptor, IrProperty>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
classes = mutableMapOf()
|
classes = mutableMapOf()
|
||||||
functions = mutableMapOf()
|
functions = mutableMapOf()
|
||||||
|
properties = mutableMapOf()
|
||||||
|
|
||||||
module.acceptVoid(object : IrElementVisitorVoid {
|
module.acceptVoid(object : IrElementVisitorVoid {
|
||||||
override fun visitElement(element: IrElement) {
|
override fun visitElement(element: IrElement) {
|
||||||
@@ -44,6 +51,11 @@ class ModuleIndex(val module: IrModuleFragment) {
|
|||||||
super.visitFunction(declaration)
|
super.visitFunction(declaration)
|
||||||
functions[declaration.descriptor] = declaration
|
functions[declaration.descriptor] = declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visitProperty(declaration: IrProperty) {
|
||||||
|
super.visitProperty(declaration)
|
||||||
|
properties[declaration.descriptor] = declaration
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -89,9 +89,12 @@ internal class ExpectToActualDefaultValueCopier(private val irModule: IrModuleFr
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified T: IrFunction> T.findActualForExpected(): T =
|
private inline fun <reified T : IrFunction> T.findActualForExpected(): T =
|
||||||
moduleIndex.functions[descriptor.findActualForExpect()] as T
|
moduleIndex.functions[descriptor.findActualForExpect()] as T
|
||||||
|
|
||||||
|
private fun IrProperty.findActualForExpected(): IrProperty =
|
||||||
|
moduleIndex.properties[descriptor.findActualForExpect()]!!
|
||||||
|
|
||||||
private fun IrClass.findActualForExpected(): IrClass =
|
private fun IrClass.findActualForExpected(): IrClass =
|
||||||
moduleIndex.classes[descriptor.findActualForExpect()]!!
|
moduleIndex.classes[descriptor.findActualForExpect()]!!
|
||||||
|
|
||||||
@@ -147,6 +150,12 @@ internal class ExpectToActualDefaultValueCopier(private val irModule: IrModuleFr
|
|||||||
else -> super.getReferencedSimpleFunction(symbol)
|
else -> super.getReferencedSimpleFunction(symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getReferencedProperty(symbol: IrPropertySymbol) =
|
||||||
|
if (symbol.descriptor.isExpect)
|
||||||
|
symbol.owner.findActualForExpected().symbol
|
||||||
|
else
|
||||||
|
super.getReferencedProperty(symbol)
|
||||||
|
|
||||||
override fun getReferencedValue(symbol: IrValueSymbol) =
|
override fun getReferencedValue(symbol: IrValueSymbol) =
|
||||||
remapExpectValue(symbol)?.symbol ?: super.getReferencedValue(symbol)
|
remapExpectValue(symbol)?.symbol ?: super.getReferencedValue(symbol)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4640,6 +4640,13 @@ linkTest("private_fake_overrides_1") {
|
|||||||
goldValue = "PASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\n"
|
goldValue = "PASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkTest("remap_expect_property_refs") {
|
||||||
|
source = "codegen/mpp/remap_expect_property_ref_main.kt"
|
||||||
|
lib = "codegen/mpp/remap_expect_property_ref_lib.kt"
|
||||||
|
flags = ["-Xmulti-platform"]
|
||||||
|
goldValue = "42\n"
|
||||||
|
}
|
||||||
|
|
||||||
Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
||||||
return KotlinNativeTestKt.createTest(project, name, FrameworkTest) { task ->
|
return KotlinNativeTestKt.createTest(project, name, FrameworkTest) { task ->
|
||||||
configurator.delegate = task
|
configurator.delegate = task
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
expect class Foo {
|
||||||
|
val p: Int
|
||||||
|
fun bar(r: () -> Int = this::p): Int
|
||||||
|
}
|
||||||
|
actual class Foo {
|
||||||
|
actual val p = 42
|
||||||
|
actual fun bar(r: () -> Int) = r()
|
||||||
|
}
|
||||||
|
fun main() {
|
||||||
|
println(Foo().bar())
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// empty
|
||||||
Reference in New Issue
Block a user