JVM_IR KT-39612 process subexpressions recursively in 'name' lowering

This commit is contained in:
Dmitry Petrov
2020-11-30 12:22:15 +03:00
parent 3b604cfa7f
commit b2aed536c9
5 changed files with 35 additions and 4 deletions
@@ -774,6 +774,11 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/callableReference/kt36975.kt");
}
@TestMetadata("kt39612.kt")
public void testKt39612() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/callableReference/kt39612.kt");
}
@TestMetadata("nameIntrinsicWithImplicitThis.kt")
public void testNameIntrinsicWithImplicitThis() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/callableReference/nameIntrinsicWithImplicitThis.kt");
@@ -55,14 +55,19 @@ private class KCallableNamePropertyTransformer(val lower: KCallableNamePropertyL
}
override fun visitCall(expression: IrCall): IrExpression {
val callableReference = expression.dispatchReceiver as? IrCallableReference<*> ?: return expression
val callableReference = expression.dispatchReceiver as? IrCallableReference<*>
?: return super.visitCall(expression)
//TODO rewrite checking
val directMember = expression.symbol.owner.let {
(it as? IrSimpleFunction)?.correspondingPropertySymbol?.owner ?: it
}
val irClass = directMember.parent as? IrClass ?: return expression
if (!irClass.isSubclassOf(lower.context.irBuiltIns.kCallableClass.owner)) return expression
val irClass = directMember.parent as? IrClass
?: return super.visitCall(expression)
if (!irClass.isSubclassOf(lower.context.irBuiltIns.kCallableClass.owner)) {
return super.visitCall(expression)
}
val name = when (directMember) {
is IrSimpleFunction -> directMember.name
is IrProperty -> directMember.name
@@ -0,0 +1,11 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun foo() {}
fun id(s: String) = s
fun test1() = id(::foo.name)
fun test2(name: String) = (if (name == ::foo.name) ::foo else ::id).annotations
// 0 getName
// 3 LDC "foo"
@@ -774,6 +774,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/callableReference/kt36975.kt");
}
@TestMetadata("kt39612.kt")
public void testKt39612() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/callableReference/kt39612.kt");
}
@TestMetadata("nameIntrinsicWithImplicitThis.kt")
public void testNameIntrinsicWithImplicitThis() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/callableReference/nameIntrinsicWithImplicitThis.kt");
@@ -774,6 +774,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/callableReference/kt36975.kt");
}
@TestMetadata("kt39612.kt")
public void testKt39612() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/callableReference/kt39612.kt");
}
@TestMetadata("nameIntrinsicWithImplicitThis.kt")
public void testNameIntrinsicWithImplicitThis() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/callableReference/nameIntrinsicWithImplicitThis.kt");