Support private package properties in inline functions
This commit is contained in:
@@ -171,7 +171,10 @@ public class JvmCodegenUtil {
|
|||||||
if (JetTypeMapper.isAccessor(property)) return false;
|
if (JetTypeMapper.isAccessor(property)) return false;
|
||||||
|
|
||||||
// Inline functions can't use direct access because a field may not be visible at the call site
|
// 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
|
// 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;
|
if (!isCallInsideSameClassAsDeclared(property, context) && !isDebuggerContext(context)) return false;
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
@@ -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 }
|
||||||
|
}
|
||||||
+21
-6
@@ -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")
|
@TestMetadata("compiler/testData/codegen/boxInline/noInline")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
@@ -796,12 +817,6 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTestMultiFileWithInlineCheck(fileName);
|
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")
|
@TestMetadata("rootConstructor.1.kt")
|
||||||
public void testRootConstructor() throws Exception {
|
public void testRootConstructor() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.1.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.1.kt");
|
||||||
|
|||||||
+21
-6
@@ -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")
|
@TestMetadata("compiler/testData/codegen/boxInline/noInline")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
@@ -796,12 +817,6 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doBoxTestWithInlineCheck(fileName);
|
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")
|
@TestMetadata("rootConstructor.1.kt")
|
||||||
public void testRootConstructor() throws Exception {
|
public void testRootConstructor() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.1.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/simple/rootConstructor.1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user