diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java index 118d4aead3b..51fe8ef0090 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java @@ -171,7 +171,10 @@ 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() && !Visibilities.isPrivate(property.getVisibility())) return false; + if (context.isInlineFunction() && + (!Visibilities.isPrivate(property.getVisibility()) || DescriptorUtils.isTopLevelDeclaration(property))) { + 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/modifiers/packagePrivateMembers.1.kt b/compiler/testData/codegen/boxInline/modifiers/packagePrivateMembers.1.kt new file mode 100644 index 00000000000..18148f951dc --- /dev/null +++ b/compiler/testData/codegen/boxInline/modifiers/packagePrivateMembers.1.kt @@ -0,0 +1,11 @@ +import test.* + +fun box(): String { + val packageResult = packageInline { a, b -> a + b } + if (packageResult != "OK") return "package inline fail: $packageResult" + + val samePackageResult = samePackageCall() + if (samePackageResult != "OK") return "same package inline fail: $samePackageResult" + + return "OK" +} diff --git a/compiler/testData/codegen/boxInline/modifiers/packagePrivateMembers.2.kt b/compiler/testData/codegen/boxInline/modifiers/packagePrivateMembers.2.kt new file mode 100644 index 00000000000..8048995811f --- /dev/null +++ b/compiler/testData/codegen/boxInline/modifiers/packagePrivateMembers.2.kt @@ -0,0 +1,13 @@ +package test + +private val packageProp = "O" + +private fun packageFun() = "K" + +inline fun packageInline(p: (String, String) -> String): String { + return p(packageProp, packageFun()) +} + +fun samePackageCall(): String { + return packageInline { s, s2 -> s + s2 } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt b/compiler/testData/codegen/boxInline/modifiers/propertyModifiers.1.kt similarity index 100% rename from compiler/testData/codegen/boxInline/simple/propertyModifiers.1.kt rename to compiler/testData/codegen/boxInline/modifiers/propertyModifiers.1.kt diff --git a/compiler/testData/codegen/boxInline/simple/propertyModifiers.2.kt b/compiler/testData/codegen/boxInline/modifiers/propertyModifiers.2.kt similarity index 100% rename from compiler/testData/codegen/boxInline/simple/propertyModifiers.2.kt rename to compiler/testData/codegen/boxInline/modifiers/propertyModifiers.2.kt diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index 8cfbcc7ed01..289388f1d0a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -383,6 +383,27 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo } } + @TestMetadata("compiler/testData/codegen/boxInline/modifiers") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Modifiers extends AbstractBlackBoxInlineCodegenTest { + public void testAllFilesPresentInModifiers() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/modifiers"), Pattern.compile("^(.+)\\.1.kt$"), true); + } + + @TestMetadata("packagePrivateMembers.1.kt") + public void testPackagePrivateMembers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/modifiers/packagePrivateMembers.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + + @TestMetadata("propertyModifiers.1.kt") + public void testPropertyModifiers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/modifiers/propertyModifiers.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/noInline") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -796,12 +817,6 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo 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/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index 67d5f2a4b06..e0c7b10ca43 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -383,6 +383,27 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi } } + @TestMetadata("compiler/testData/codegen/boxInline/modifiers") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Modifiers extends AbstractCompileKotlinAgainstInlineKotlinTest { + public void testAllFilesPresentInModifiers() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/modifiers"), Pattern.compile("^(.+)\\.1.kt$"), true); + } + + @TestMetadata("packagePrivateMembers.1.kt") + public void testPackagePrivateMembers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/modifiers/packagePrivateMembers.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + + @TestMetadata("propertyModifiers.1.kt") + public void testPropertyModifiers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/modifiers/propertyModifiers.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/noInline") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -796,12 +817,6 @@ 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");