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
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
+6
@@ -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");
|
||||
|
||||
+6
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user