From 59917f3727b9a04dfd9eec23de0ab3f196e2df2a Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Thu, 30 Oct 2014 12:30:45 +0300 Subject: [PATCH] Fix for KT-6154: Inlining a private class function accessing a private val member throws exception at runtime in accessing the val getter #KT-6154 Fixed --- .../jetbrains/jet/codegen/JvmCodegenUtil.java | 2 +- .../boxInline/simple/propertyModifiers.1.kt | 10 ++++++++ .../boxInline/simple/propertyModifiers.2.kt | 23 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 6 +++++ ...otlinAgainstInlineKotlinTestGenerated.java | 6 +++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt create mode 100644 compiler/testData/codegen/boxInline/simple/propertyModifiers.2.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JvmCodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/JvmCodegenUtil.java index 8a5205bbf59..52cdadebfbe 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JvmCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JvmCodegenUtil.java @@ -166,7 +166,7 @@ public class JvmCodegenUtil { if (JetTypeMapper.isAccessor(property)) return false; // Inline functions can't use direct access because a field may not be visible at the call site - if (context.isInlineFunction()) return false; + if (context.isInlineFunction() && property.getVisibility() != Visibilities.PRIVATE) return false; // Only properties of the same class can be directly accessed, except when we are evaluating expressions in the debugger if (!isCallInsideSameClassAsDeclared(property, context) && !isDebuggerContext(context)) return false; diff --git a/compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt b/compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt new file mode 100644 index 00000000000..304f6cb3502 --- /dev/null +++ b/compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt @@ -0,0 +1,10 @@ +import test.* + +fun box() : String { + val p = P() + + if (p.testPrivate() != "OK") return "fail 1 ${p.testPrivate()}" + + if (p.testFinal() != "OK") return "fail 2 ${p.testFinal()}" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/simple/propertyModifiers.2.kt b/compiler/testData/codegen/boxInline/simple/propertyModifiers.2.kt new file mode 100644 index 00000000000..f66496a0b13 --- /dev/null +++ b/compiler/testData/codegen/boxInline/simple/propertyModifiers.2.kt @@ -0,0 +1,23 @@ +package test + +class P { + private val FOO_PRIVATE = "OK" + + final val FOO_FINAL = "OK" + + private inline fun fooPrivate(): String { + return FOO_PRIVATE + } + + private inline fun fooFinal(): String { + return FOO_FINAL + } + + fun testPrivate(): String { + return fooPrivate() + } + + fun testFinal(): String { + return fooFinal() + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index eaea62dfd38..70473eb5c88 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -632,6 +632,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxCodegenT doTestMultiFileWithInlineCheck(fileName); } + @TestMetadata("propertyModifiers.1.kt") + public void testPropertyModifiers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + @TestMetadata("rootConstructor.1.kt") public void testRootConstructor() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.1.kt"); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index 8b30844ba5e..f1b8fc2d335 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -632,6 +632,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doBoxTestWithInlineCheck(fileName); } + @TestMetadata("propertyModifiers.1.kt") + public void testPropertyModifiers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + @TestMetadata("rootConstructor.1.kt") public void testRootConstructor() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.1.kt");