Prevent generation of delegations to interfaces private methods
#KT-13381 Fixed #KT-13996 Fixed
This commit is contained in:
@@ -106,7 +106,9 @@ object CodegenUtil {
|
||||
if (declaration !is CallableMemberDescriptor) continue
|
||||
|
||||
val traitMember = findInterfaceImplementation(declaration)
|
||||
if (traitMember == null || Visibilities.isPrivate(traitMember.visibility)) continue
|
||||
if (traitMember == null ||
|
||||
Visibilities.isPrivate(traitMember.visibility) ||
|
||||
traitMember.visibility == Visibilities.INVISIBLE_FAKE) continue
|
||||
|
||||
assert(traitMember.modality !== Modality.ABSTRACT) { "Cannot delegate to abstract trait method: $declaration" }
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
interface A {
|
||||
// There must be no delegation methods for 'log' and 'bar' in C as they are private
|
||||
private val log: String get() = "O"
|
||||
private fun bar() = "K"
|
||||
|
||||
fun foo() = log + bar()
|
||||
}
|
||||
|
||||
interface B : A
|
||||
class C : B
|
||||
|
||||
fun box() = C().foo()
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
interface A {
|
||||
// There must be no delegation methods for 'log' and 'bar' in C as they are private
|
||||
private val log: String get() = "O"
|
||||
private fun bar() = "K"
|
||||
|
||||
fun foo() = log + bar()
|
||||
}
|
||||
|
||||
interface B : A
|
||||
class C : B
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
@kotlin.Metadata
|
||||
public final class A$DefaultImpls {
|
||||
inner class A$DefaultImpls
|
||||
private static method bar(p0: A): java.lang.String
|
||||
public static @org.jetbrains.annotations.NotNull method foo(p0: A): java.lang.String
|
||||
private static method getLog(p0: A): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface A {
|
||||
inner class A$DefaultImpls
|
||||
public abstract @org.jetbrains.annotations.NotNull method foo(): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class B$DefaultImpls {
|
||||
inner class B$DefaultImpls
|
||||
public static @org.jetbrains.annotations.NotNull method foo(p0: B): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public interface B {
|
||||
inner class B$DefaultImpls
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class C {
|
||||
public method <init>(): void
|
||||
public @org.jetbrains.annotations.NotNull method foo(): java.lang.String
|
||||
}
|
||||
@@ -13666,6 +13666,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt13381.kt")
|
||||
public void testKt13381() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt13381.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt1406.kt")
|
||||
public void testKt1406() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt1406.kt");
|
||||
|
||||
@@ -77,6 +77,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noDelegationsToPrivateInterfaceMembers.kt")
|
||||
public void testNoDelegationsToPrivateInterfaceMembers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/noDelegationsToPrivateInterfaceMembers.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("samAdapterAndInlinedOne.kt")
|
||||
public void testSamAdapterAndInlinedOne() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/samAdapterAndInlinedOne.kt");
|
||||
|
||||
Reference in New Issue
Block a user