From eaf9c2e8b097af27b5cd76e9068df6ab9284882d Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Tue, 25 Oct 2016 12:15:21 +0300 Subject: [PATCH] Fix for KT-13890: IllegalAccessError when invoking protected method with default arguments #KT-13890 Fixed --- .../kotlin/codegen/FunctionCodegen.java | 9 ++++---- .../codegen/box/defaultArguments/protected.kt | 23 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 +++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/box/defaultArguments/protected.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 56fec60af3e..6bf97bdfbfd 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -845,14 +845,13 @@ public class FunctionCodegen { return; } - int flags = getVisibilityAccessFlag(functionDescriptor) | - getDeprecatedAccessFlag(functionDescriptor) | - ACC_SYNTHETIC; + // $default methods are never private to be accessible from other class files (e.g. inner) without the need of synthetic accessors + // $default methods are never protected to be accessible from subclass nested classes + int visibilityFlag = Visibilities.isPrivate(functionDescriptor.getVisibility()) ? AsmUtil.NO_FLAG_PACKAGE_PRIVATE : Opcodes.ACC_PUBLIC; + int flags = visibilityFlag | getDeprecatedAccessFlag(functionDescriptor) | ACC_SYNTHETIC; if (!(functionDescriptor instanceof ConstructorDescriptor)) { flags |= ACC_STATIC | ACC_BRIDGE; } - // $default methods are never private to be accessible from other class files (e.g. inner) without the need of synthetic accessors - flags &= ~ACC_PRIVATE; Method defaultMethod = typeMapper.mapDefaultMethod(functionDescriptor, kind); diff --git a/compiler/testData/codegen/box/defaultArguments/protected.kt b/compiler/testData/codegen/box/defaultArguments/protected.kt new file mode 100644 index 00000000000..be1243f96c6 --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/protected.kt @@ -0,0 +1,23 @@ +// FILE: Foo.kt + +package foo + +open class Foo() { + protected fun foo(value: Boolean = false) = if (!value) "OK" else "fail5" +} + +// FILE: Bar.kt + +package bar + +import foo.Foo + +class Bar() : Foo() { + fun execute(): String { + return { foo() } () + } +} + +fun box(): String { + return Bar().execute() +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index eea7645e8f7..9d8e0a8cf39 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -5113,6 +5113,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("protected.kt") + public void testProtected() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/protected.kt"); + doTest(fileName); + } + @TestMetadata("simpleFromOtherFile.kt") public void testSimpleFromOtherFile() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/simpleFromOtherFile.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index e8eaa90bebd..278038e6b77 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -5113,6 +5113,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("protected.kt") + public void testProtected() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/protected.kt"); + doTest(fileName); + } + @TestMetadata("simpleFromOtherFile.kt") public void testSimpleFromOtherFile() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/simpleFromOtherFile.kt");