Forbid val field initialization inside EXACLTY_ONCE lambda

unless the lambda is inline. This way, final field will remain final.
This commit is contained in:
Ilmir Usmanov
2020-06-03 18:32:43 +02:00
parent 6d6a228057
commit 8cc5f2abfb
18 changed files with 177 additions and 76 deletions
@@ -422,14 +422,6 @@ public class PropertyCodegen {
}
modifiers |= getVisibilityForBackingField(propertyDescriptor, isDelegate);
// If val is initialized in EXACTLY_ONCE closure, other class from the same package initializes it
// so, its visibility should be package private and not final
if (!propertyDescriptor.isVar() &&
bindingContext.get(BindingContext.FIELD_CAPTURED_IN_EXACLY_ONCE_CLOSURE, propertyDescriptor) != null
) {
modifiers &= ~(ACC_PRIVATE | ACC_FINAL);
}
if (AsmUtil.isPropertyWithBackingFieldCopyInOuterClass(propertyDescriptor)) {
ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
parentBodyCodegen.addCompanionObjectPropertyToCopy(propertyDescriptor, defaultValue);