Use access to backing field on overridden property with private setter
#KT-27772 Fixed
This commit is contained in:
@@ -244,7 +244,7 @@ public class JvmCodegenUtil {
|
|||||||
if (DescriptorPsiUtilsKt.hasBody(accessor)) return false;
|
if (DescriptorPsiUtilsKt.hasBody(accessor)) return false;
|
||||||
|
|
||||||
// If the accessor is private or final, it can't be overridden in the subclass and thus we can use direct access
|
// If the accessor is private or final, it can't be overridden in the subclass and thus we can use direct access
|
||||||
return Visibilities.isPrivate(property.getVisibility()) || accessor.getModality() == FINAL;
|
return Visibilities.isPrivate(accessor.getVisibility()) || accessor.getModality() == FINAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isDebuggerContext(@NotNull CodegenContext context) {
|
private static boolean isDebuggerContext(@NotNull CodegenContext context) {
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
interface A {
|
||||||
|
val foo: String
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A {
|
||||||
|
override var foo: String = "Fail"
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun setOK(other: B) {
|
||||||
|
other.foo = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val b = B()
|
||||||
|
b.setOK(b)
|
||||||
|
return b.foo
|
||||||
|
}
|
||||||
+5
@@ -17530,6 +17530,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAccessorOfOverriddenProperty.kt")
|
||||||
|
public void testPrivateAccessorOfOverriddenProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/properties/privateAccessorOfOverriddenProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privatePropertyInConstructor.kt")
|
@TestMetadata("privatePropertyInConstructor.kt")
|
||||||
public void testPrivatePropertyInConstructor() throws Exception {
|
public void testPrivatePropertyInConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
||||||
|
|||||||
+5
@@ -17530,6 +17530,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAccessorOfOverriddenProperty.kt")
|
||||||
|
public void testPrivateAccessorOfOverriddenProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/properties/privateAccessorOfOverriddenProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privatePropertyInConstructor.kt")
|
@TestMetadata("privatePropertyInConstructor.kt")
|
||||||
public void testPrivatePropertyInConstructor() throws Exception {
|
public void testPrivatePropertyInConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
||||||
|
|||||||
+5
@@ -17535,6 +17535,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAccessorOfOverriddenProperty.kt")
|
||||||
|
public void testPrivateAccessorOfOverriddenProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/properties/privateAccessorOfOverriddenProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privatePropertyInConstructor.kt")
|
@TestMetadata("privatePropertyInConstructor.kt")
|
||||||
public void testPrivatePropertyInConstructor() throws Exception {
|
public void testPrivatePropertyInConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
||||||
|
|||||||
+5
@@ -15105,6 +15105,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAccessorOfOverriddenProperty.kt")
|
||||||
|
public void testPrivateAccessorOfOverriddenProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/properties/privateAccessorOfOverriddenProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privatePropertyInConstructor.kt")
|
@TestMetadata("privatePropertyInConstructor.kt")
|
||||||
public void testPrivatePropertyInConstructor() throws Exception {
|
public void testPrivatePropertyInConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
||||||
|
|||||||
+5
@@ -16150,6 +16150,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
runTest("compiler/testData/codegen/box/properties/primitiveOverrideDelegateAccessor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAccessorOfOverriddenProperty.kt")
|
||||||
|
public void testPrivateAccessorOfOverriddenProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/properties/privateAccessorOfOverriddenProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privatePropertyInConstructor.kt")
|
@TestMetadata("privatePropertyInConstructor.kt")
|
||||||
public void testPrivatePropertyInConstructor() throws Exception {
|
public void testPrivatePropertyInConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
runTest("compiler/testData/codegen/box/properties/privatePropertyInConstructor.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user