Suggest names for captured receivers.

This commit is contained in:
Dmitry Petrov
2016-10-06 11:55:47 +03:00
parent 1658e110f2
commit fedfd3de16
3 changed files with 23 additions and 1 deletions
@@ -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
)
+6
View File
@@ -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");