diff --git a/compiler/testData/codegen/box/properties/substituteJavaSuperField.kt b/compiler/testData/codegen/box/properties/substituteJavaSuperField.kt index dc97cae19cd..b0903703b20 100644 --- a/compiler/testData/codegen/box/properties/substituteJavaSuperField.kt +++ b/compiler/testData/codegen/box/properties/substituteJavaSuperField.kt @@ -5,11 +5,15 @@ public abstract class Test { } // FILE: test.kt +// See KT-5445: Bad access to protected data in getfield class A : Test() { fun foo(): String? = value + fun bar(): String? = this.value } fun box(): String { - return if (A().foo() == null) "OK" else "Fail" + if (A().foo() != null) return "Fail 1" + if (A().bar() != null) return "Fail 2" + return "OK" } diff --git a/compiler/testData/codegen/boxAgainstJava/visibility/protectedAndPackage/protectedSuperMethod.kt b/compiler/testData/codegen/boxAgainstJava/visibility/protectedAndPackage/protectedSuperMethod.kt new file mode 100644 index 00000000000..330c6ebfeca --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/visibility/protectedAndPackage/protectedSuperMethod.kt @@ -0,0 +1,31 @@ +// FILE: test/Foo.java + +package test; + +public class Foo { + protected void foo(Runnable r) { + r.run(); + } +} + +// FILE: test.kt + +package other + +import test.Foo + +class Bar : Foo() { + fun bar() { + foo {} + foo(Runnable {}) + // super.foo {} + super.foo(Runnable {}) + this.foo {} + this.foo(Runnable {}) + } +} + +fun box(): String { + Bar().bar() + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java index fbfb48857a2..99315396b8c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java @@ -935,6 +935,12 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxAga String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/visibility/protectedAndPackage/protectedStaticClass.kt"); doTest(fileName); } + + @TestMetadata("protectedSuperMethod.kt") + public void testProtectedSuperMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/visibility/protectedAndPackage/protectedSuperMethod.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/boxAgainstJava/visibility/protectedStatic")