KT-53007 Fix accessibility checks when calling a protected member via super@Outer

This commit is contained in:
Pavel Mikhailovskii
2022-07-13 13:08:59 +02:00
parent 603d043abc
commit b26155dd9e
6 changed files with 42 additions and 1 deletions
@@ -5781,6 +5781,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/classes/kt508.kt");
}
@Test
@TestMetadata("kt53007.kt")
public void testKt53007() throws Exception {
runTest("compiler/testData/codegen/box/classes/kt53007.kt");
}
@Test
@TestMetadata("kt5347.kt")
public void testKt5347() throws Exception {
@@ -91,8 +91,8 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : FileL
val scopeClassOrPackage = inlineScopeResolver.findContainer(currentScope!!.irElement) ?: return false
val samePackage = ownerClass.getPackageFragment().fqName == scopeClassOrPackage.getPackageFragment()?.fqName
return when {
jvmVisibility == 0 /* package only */ -> samePackage
jvmVisibility == Opcodes.ACC_PRIVATE -> ownerClass == scopeClassOrPackage
!withSuper && samePackage && jvmVisibility == 0 /* package only */ -> true
// JVM `protected`, unlike Kotlin `protected`, permits accesses from the same package,
// provided the call is not across class loader boundaries.
!withSuper && samePackage && !fromOtherClassLoader -> true
+18
View File
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// FILE: SubClass.kt
class SubClass: BaseClass() {
inner class InnerClass {
fun foo() = super@SubClass.foo()
}
}
fun box() = SubClass().InnerClass().foo()
// FILE: BaseClass.java
public class BaseClass {
String foo() {
return "OK";
}
}
@@ -5667,6 +5667,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/classes/kt508.kt");
}
@Test
@TestMetadata("kt53007.kt")
public void testKt53007() throws Exception {
runTest("compiler/testData/codegen/box/classes/kt53007.kt");
}
@Test
@TestMetadata("kt5347.kt")
public void testKt5347() throws Exception {
@@ -5781,6 +5781,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/classes/kt508.kt");
}
@Test
@TestMetadata("kt53007.kt")
public void testKt53007() throws Exception {
runTest("compiler/testData/codegen/box/classes/kt53007.kt");
}
@Test
@TestMetadata("kt5347.kt")
public void testKt5347() throws Exception {
@@ -4951,6 +4951,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/classes/kt508.kt");
}
@TestMetadata("kt53007.kt")
public void testKt53007() throws Exception {
runTest("compiler/testData/codegen/box/classes/kt53007.kt");
}
@TestMetadata("kt5347.kt")
public void testKt5347() throws Exception {
runTest("compiler/testData/codegen/box/classes/kt5347.kt");