Fix inheritance from protected members of interfaces
#KT-3029 Fixed
This commit is contained in:
@@ -32,12 +32,12 @@ import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods;
|
|||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
|
import org.jetbrains.kotlin.jvm.RuntimeAssertionInfo;
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||||
import org.jetbrains.kotlin.load.java.JavaVisibilities;
|
import org.jetbrains.kotlin.load.java.JavaVisibilities;
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||||
import org.jetbrains.kotlin.jvm.RuntimeAssertionInfo;
|
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
|
import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
|
||||||
@@ -330,13 +330,21 @@ public class AsmUtil {
|
|||||||
PropertyDescriptor property = ((PropertyAccessorDescriptor) memberDescriptor).getCorrespondingProperty();
|
PropertyDescriptor property = ((PropertyAccessorDescriptor) memberDescriptor).getCorrespondingProperty();
|
||||||
if (property instanceof SyntheticJavaPropertyDescriptor) {
|
if (property instanceof SyntheticJavaPropertyDescriptor) {
|
||||||
FunctionDescriptor method = memberDescriptor == property.getGetter()
|
FunctionDescriptor method = memberDescriptor == property.getGetter()
|
||||||
? ((SyntheticJavaPropertyDescriptor) property).getGetMethod()
|
? ((SyntheticJavaPropertyDescriptor) property).getGetMethod()
|
||||||
: ((SyntheticJavaPropertyDescriptor) property).getSetMethod();
|
: ((SyntheticJavaPropertyDescriptor) property).getSetMethod();
|
||||||
assert method != null : "No setMethod in SyntheticJavaPropertyDescriptor";
|
assert method != null : "No get/set method in SyntheticJavaPropertyDescriptor: " + property;
|
||||||
return getVisibilityAccessFlag(method);
|
return getVisibilityAccessFlag(method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (memberDescriptor instanceof CallableDescriptor && memberVisibility == Visibilities.PROTECTED) {
|
||||||
|
for (CallableDescriptor overridden : DescriptorUtils.getAllOverriddenDescriptors((CallableDescriptor) memberDescriptor)) {
|
||||||
|
if (isInterface(overridden.getContainingDeclaration())) {
|
||||||
|
return ACC_PUBLIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!Visibilities.isPrivate(memberVisibility)) {
|
if (!Visibilities.isPrivate(memberVisibility)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
interface A {
|
||||||
|
protected fun foo()
|
||||||
|
|
||||||
|
protected fun fooImpl() { }
|
||||||
|
|
||||||
|
protected var bar: Int
|
||||||
|
|
||||||
|
public var baz: String
|
||||||
|
public get() = ""
|
||||||
|
protected set(value) {}
|
||||||
|
|
||||||
|
fun test(): String {
|
||||||
|
foo()
|
||||||
|
fooImpl()
|
||||||
|
bar = bar + 1
|
||||||
|
baz = baz + "1"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A {
|
||||||
|
protected override fun foo() {}
|
||||||
|
|
||||||
|
protected override var bar: Int = 42
|
||||||
|
|
||||||
|
override var baz: String = ""
|
||||||
|
protected set
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = B().test()
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
interface Foo {
|
||||||
|
protected class Bar {
|
||||||
|
fun box() = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Baz : Foo {
|
||||||
|
fun box() = Foo.Bar().box()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = Baz().box()
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
interface A {
|
||||||
|
protected fun foo(): String
|
||||||
|
|
||||||
|
fun box() = foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface B : A
|
||||||
|
|
||||||
|
interface C : A {
|
||||||
|
protected override fun foo() = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
class D : B, C
|
||||||
|
|
||||||
|
fun box() = D().box()
|
||||||
+18
@@ -7420,6 +7420,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inheritProtectedInterfaceMembers.kt")
|
||||||
|
public void testInheritProtectedInterfaceMembers() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/inheritProtectedInterfaceMembers.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inheritedFun.kt")
|
@TestMetadata("inheritedFun.kt")
|
||||||
public void testInheritedFun() throws Exception {
|
public void testInheritedFun() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/inheritedFun.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/inheritedFun.kt");
|
||||||
@@ -7516,6 +7522,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("protectedClassInInterface.kt")
|
||||||
|
public void testProtectedClassInInterface() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/protectedClassInInterface.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("protectedFunDiamond.kt")
|
||||||
|
public void testProtectedFunDiamond() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/protectedFunDiamond.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("traitImplDelegationWithCovariantOverride.kt")
|
@TestMetadata("traitImplDelegationWithCovariantOverride.kt")
|
||||||
public void testTraitImplDelegationWithCovariantOverride() throws Exception {
|
public void testTraitImplDelegationWithCovariantOverride() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/traitImplDelegationWithCovariantOverride.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/traitImplDelegationWithCovariantOverride.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user