Fix for KT-8928: NoSuchMethodError on private property setter in companion object

#KT-8928 Fixed
This commit is contained in:
Michael Bogdanov
2015-11-03 13:10:48 +03:00
parent 559b85caa8
commit 86f8845c00
3 changed files with 32 additions and 2 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm.checkers;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
import org.jetbrains.kotlin.descriptors.Visibilities;
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext;
@@ -30,7 +31,7 @@ import static org.jetbrains.kotlin.resolve.BindingContext.NEED_SYNTHETIC_ACCESSO
public class NeedSyntheticChecker implements CallChecker {
@Override
public <F extends CallableDescriptor> void check(
public <F extends CallableDescriptor> void check(
@NotNull ResolvedCall<F> resolvedCall,
@NotNull BasicCallResolutionContext context
) {
@@ -45,7 +46,14 @@ public class NeedSyntheticChecker implements CallChecker {
// e.g.: from class to companion object) controlled via NEED_SYNTHETIC_ACCESSOR slice
private static boolean needSyntheticAccessor(LexicalScope invokationScope, CallableDescriptor targetDescriptor) {
return targetDescriptor instanceof CallableMemberDescriptor &&
Visibilities.isPrivate(targetDescriptor.getVisibility()) &&
isPrivate(targetDescriptor) &&
targetDescriptor.getContainingDeclaration() != invokationScope.getOwnerDescriptor().getContainingDeclaration();
}
private static boolean isPrivate(@NotNull CallableDescriptor targetDescriptor) {
return Visibilities.isPrivate(targetDescriptor.getVisibility()) ||
(targetDescriptor instanceof PropertyDescriptor &&
((PropertyDescriptor) targetDescriptor).getSetter() != null &&
Visibilities.isPrivate(((PropertyDescriptor) targetDescriptor).getSetter().getVisibility()));
}
}
+16
View File
@@ -0,0 +1,16 @@
class App {
fun init() {
s = "OK"
}
companion object {
var s: String = "Fail"
private set
}
}
fun box(): String {
App().init()
return App.s
}
@@ -6742,6 +6742,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt8928.kt")
public void testKt8928() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/kt8928.kt");
doTest(fileName);
}
@TestMetadata("kt9603.kt")
public void testKt9603() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/properties/kt9603.kt");