Fix isInitialized for companion lateinit properties
Instead of trying to access a missing field `Foo.foo`, call the synthetic accessor `Foo.access$getFoo$cp` which, as per previous commit, no longer contains the lateinit assertion #KT-21862 Fixed
This commit is contained in:
@@ -2084,10 +2084,19 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
couldUseDirectAccessToProperty(propertyDescriptor, false, isDelegatedProperty, context, state.getShouldInlineConstVals());
|
||||
|
||||
if (fieldAccessorKind == AccessorKind.LATEINIT_INTRINSIC) {
|
||||
skipPropertyAccessors = !isPrivateProperty || context.getClassOrPackageParentContext() == backingFieldContext;
|
||||
skipPropertyAccessors =
|
||||
(!isPrivateProperty || context.getClassOrPackageParentContext() == backingFieldContext) &&
|
||||
!isBackingFieldMovedFromCompanion;
|
||||
|
||||
if (!skipPropertyAccessors) {
|
||||
propertyDescriptor = backingFieldContext.getAccessor(propertyDescriptor, fieldAccessorKind, delegateType, superCallTarget);
|
||||
if (isBackingFieldMovedFromCompanion && context.getContextDescriptor() instanceof AccessorForPropertyBackingField) {
|
||||
propertyDescriptor = (PropertyDescriptor) backingFieldContext.getParentContext()
|
||||
.getAccessor(propertyDescriptor, AccessorKind.IN_CLASS_COMPANION, delegateType, superCallTarget);
|
||||
}
|
||||
else {
|
||||
propertyDescriptor =
|
||||
backingFieldContext.getAccessor(propertyDescriptor, fieldAccessorKind, delegateType, superCallTarget);
|
||||
}
|
||||
}
|
||||
ownerDescriptor = propertyDescriptor;
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Class {
|
||||
companion object {
|
||||
lateinit var public: String
|
||||
private lateinit var private: String
|
||||
|
||||
fun test() {
|
||||
if (::public.isInitialized) throw AssertionError("Fail 1")
|
||||
public = "OK"
|
||||
if (public != "OK") throw AssertionError("Fail 2")
|
||||
|
||||
if (::private.isInitialized) throw AssertionError("Fail 3")
|
||||
private = "OK"
|
||||
if (private != "OK") throw AssertionError("Fail 4")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Interface {
|
||||
companion object {
|
||||
lateinit var public: String
|
||||
private lateinit var private: String
|
||||
|
||||
fun test() {
|
||||
if (::public.isInitialized) throw AssertionError("Fail 5")
|
||||
public = "OK"
|
||||
if (public != "OK") throw AssertionError("Fail 6")
|
||||
|
||||
if (::private.isInitialized) throw AssertionError("Fail 7")
|
||||
private = "OK"
|
||||
if (private != "OK") throw AssertionError("Fail 8")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Class.test()
|
||||
Interface.test()
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -17860,6 +17860,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectField.kt")
|
||||
public void testCompanionObjectField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/companionObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptyLhs.kt")
|
||||
public void testEmptyLhs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/emptyLhs.kt");
|
||||
|
||||
+5
@@ -17860,6 +17860,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectField.kt")
|
||||
public void testCompanionObjectField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/companionObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptyLhs.kt")
|
||||
public void testEmptyLhs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/emptyLhs.kt");
|
||||
|
||||
+5
@@ -17865,6 +17865,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectField.kt")
|
||||
public void testCompanionObjectField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/companionObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptyLhs.kt")
|
||||
public void testEmptyLhs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/emptyLhs.kt");
|
||||
|
||||
+5
@@ -15350,6 +15350,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectField.kt")
|
||||
public void testCompanionObjectField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/companionObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptyLhs.kt")
|
||||
public void testEmptyLhs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/emptyLhs.kt");
|
||||
|
||||
+5
@@ -16410,6 +16410,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectField.kt")
|
||||
public void testCompanionObjectField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/companionObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptyLhs.kt")
|
||||
public void testEmptyLhs() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/emptyLhs.kt");
|
||||
|
||||
Reference in New Issue
Block a user