Fix for KT-5150: Accessors for private methods are not generated for get/set conventions
#KT-5150 Fixed
This commit is contained in:
@@ -2357,7 +2357,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private FunctionDescriptor accessibleFunctionDescriptor(@NotNull ResolvedCall<?> resolvedCall) {
|
protected FunctionDescriptor accessibleFunctionDescriptor(@NotNull ResolvedCall<?> resolvedCall) {
|
||||||
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
FunctionDescriptor descriptor = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
||||||
FunctionDescriptor originalIfSamAdapter = SamCodegenUtil.getOriginalIfSamAdapter(descriptor);
|
FunctionDescriptor originalIfSamAdapter = SamCodegenUtil.getOriginalIfSamAdapter(descriptor);
|
||||||
if (originalIfSamAdapter != null) {
|
if (originalIfSamAdapter != null) {
|
||||||
|
|||||||
@@ -911,8 +911,6 @@ public abstract class StackValue {
|
|||||||
private final ExpressionCodegen codegen;
|
private final ExpressionCodegen codegen;
|
||||||
private final ResolvedCall<FunctionDescriptor> resolvedGetCall;
|
private final ResolvedCall<FunctionDescriptor> resolvedGetCall;
|
||||||
private final ResolvedCall<FunctionDescriptor> resolvedSetCall;
|
private final ResolvedCall<FunctionDescriptor> resolvedSetCall;
|
||||||
private final FunctionDescriptor setterDescriptor;
|
|
||||||
private final FunctionDescriptor getterDescriptor;
|
|
||||||
|
|
||||||
public CollectionElement(
|
public CollectionElement(
|
||||||
@NotNull CollectionElementReceiver collectionElementReceiver,
|
@NotNull CollectionElementReceiver collectionElementReceiver,
|
||||||
@@ -924,10 +922,10 @@ public abstract class StackValue {
|
|||||||
super(type, false, false, collectionElementReceiver, true);
|
super(type, false, false, collectionElementReceiver, true);
|
||||||
this.resolvedGetCall = resolvedGetCall;
|
this.resolvedGetCall = resolvedGetCall;
|
||||||
this.resolvedSetCall = resolvedSetCall;
|
this.resolvedSetCall = resolvedSetCall;
|
||||||
this.setterDescriptor = resolvedSetCall == null ? null : resolvedSetCall.getResultingDescriptor();
|
this.setter = resolvedSetCall == null ? null :
|
||||||
this.getterDescriptor = resolvedGetCall == null ? null : resolvedGetCall.getResultingDescriptor();
|
codegen.resolveToCallable(codegen.accessibleFunctionDescriptor(resolvedSetCall), false, resolvedSetCall);
|
||||||
this.setter = resolvedSetCall == null ? null : codegen.resolveToCallable(setterDescriptor, false, resolvedSetCall);
|
this.getter = resolvedGetCall == null ? null :
|
||||||
this.getter = resolvedGetCall == null ? null : codegen.resolveToCallable(getterDescriptor, false, resolvedGetCall);
|
codegen.resolveToCallable(codegen.accessibleFunctionDescriptor(resolvedGetCall), false, resolvedGetCall);
|
||||||
this.codegen = codegen;
|
this.codegen = codegen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
var result = "fail"
|
||||||
|
|
||||||
|
private operator fun X.get(name: String) = name + "K"
|
||||||
|
private operator fun X.set(name: String, v: String) {
|
||||||
|
result = v
|
||||||
|
}
|
||||||
|
|
||||||
|
class X {
|
||||||
|
fun test() : String {
|
||||||
|
if (this["O"] != "OK") return "fail 1: ${this["O"]}"
|
||||||
|
|
||||||
|
this["O"] += "K"
|
||||||
|
if (result != "OKK") return "fail 2: ${result}"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return X().test()
|
||||||
|
}
|
||||||
+15
@@ -6422,6 +6422,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/private")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Private extends AbstractBlackBoxCodegenTest {
|
||||||
|
public void testAllFilesPresentInPrivate() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/private"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("arrayConvention.kt")
|
||||||
|
public void testArrayConvention() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/private/arrayConvention.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/privateConstructors")
|
@TestMetadata("compiler/testData/codegen/box/privateConstructors")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user