Suggest names for captured receivers.
This commit is contained in:
+11
-1
@@ -296,6 +296,14 @@ class LocalFunctionsLowering(val context: JvmBackendContext): ClassLoweringPass
|
||||
return newDescriptor
|
||||
}
|
||||
|
||||
private fun suggestNameForCapturedValueParameter(valueDescriptor: ValueDescriptor): Name =
|
||||
if (valueDescriptor.name.isSpecial) {
|
||||
val oldNameStr = valueDescriptor.name.asString()
|
||||
Name.identifier("$" + oldNameStr.substring(1, oldNameStr.length - 1))
|
||||
}
|
||||
else
|
||||
valueDescriptor.name
|
||||
|
||||
private fun createUnsubstitutedCapturedValueParameter(
|
||||
newParameterOwner: CallableMemberDescriptor,
|
||||
valueDescriptor: ValueDescriptor,
|
||||
@@ -303,7 +311,9 @@ class LocalFunctionsLowering(val context: JvmBackendContext): ClassLoweringPass
|
||||
): ValueParameterDescriptor =
|
||||
ValueParameterDescriptorImpl(
|
||||
newParameterOwner, null, index,
|
||||
valueDescriptor.annotations, valueDescriptor.name, valueDescriptor.type,
|
||||
valueDescriptor.annotations,
|
||||
suggestNameForCapturedValueParameter(valueDescriptor),
|
||||
valueDescriptor.type,
|
||||
false, false, false, false, null, valueDescriptor.source
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
fun String.foo(): String {
|
||||
fun bar(y: String) = this + y
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box() = "O".foo()
|
||||
@@ -59,6 +59,12 @@ public class IrOnlyBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTest
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closureConversion4.kt")
|
||||
public void testClosureConversion4() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/box/closureConversion4.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("enumClass.kt")
|
||||
public void testEnumClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/box/enumClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user