JVM, JVM_IR: no nullability annotations on lateinit backing fields

This commit is contained in:
Dmitry Petrov
2020-06-26 10:49:51 +03:00
parent e822e871f5
commit 64e47265e1
3 changed files with 10 additions and 5 deletions
@@ -438,8 +438,13 @@ public class PropertyCodegen {
);
if (annotatedField != null) {
boolean isInvisibleField = (modifiers & ACC_PRIVATE) != 0 || (modifiers & ACC_SYNTHETIC) != 0;
AnnotationCodegen.forField(fv, memberCodegen, state, isInvisibleField)
// Don't emit nullability annotations for backing field if:
// - backing field is invisible from Java (private or synthetic);
// - property is lateinit (since corresponding field is actually nullable).
boolean skipNullabilityAnnotations =
(modifiers & ACC_PRIVATE) != 0 || (modifiers & ACC_SYNTHETIC) != 0 ||
propertyDescriptor.isLateInit();
AnnotationCodegen.forField(fv, memberCodegen, state, skipNullabilityAnnotations)
.genAnnotations(annotatedField, type, propertyDescriptor.getType());
}
}