Revert "JVM: remove support for disabling NoConstantValueAttributeForNonConstVals"
This is a partial revert of e857966edb.
Specifically, behavior is restored in the old backend, which will allow
to support language version 1.3, where this language feature was not
enabled yet. There are no changes in the JVM IR backend, because to
enable JVM IR with LV 1.3, you need to pass the compiler argument
`-Xuse-ir` which is not stable and we don't guarantee anything about it.
#KT-50251
This commit is contained in:
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.codegen.context.MultifileClassFacadeContext;
|
||||
import org.jetbrains.kotlin.codegen.context.MultifileClassPartContext;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
|
||||
import org.jetbrains.kotlin.config.LanguageFeature;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.load.java.DescriptorsJvmAbiUtil;
|
||||
@@ -343,7 +344,7 @@ public class PropertyCodegen {
|
||||
defaultValue = null;
|
||||
}
|
||||
else if (Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor))) {
|
||||
if (descriptor.isConst()) {
|
||||
if (shouldWriteFieldInitializer(descriptor)) {
|
||||
ConstantValue<?> initializer = descriptor.getCompileTimeInitializer();
|
||||
defaultValue = initializer == null ? null : initializer.getValue();
|
||||
}
|
||||
@@ -487,6 +488,20 @@ public class PropertyCodegen {
|
||||
return delegateType;
|
||||
}
|
||||
|
||||
private boolean shouldWriteFieldInitializer(@NotNull PropertyDescriptor descriptor) {
|
||||
if (!descriptor.isConst() &&
|
||||
state.getLanguageVersionSettings().supportsFeature(LanguageFeature.NoConstantValueAttributeForNonConstVals)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//final field of primitive or String type
|
||||
if (!descriptor.isVar()) {
|
||||
Type type = typeMapper.mapType(descriptor);
|
||||
return AsmUtil.isPrimitive(type) || "java.lang.String".equals(type.getClassName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void generateGetter(@NotNull PropertyDescriptor descriptor, @Nullable KtPropertyAccessor getter) {
|
||||
generateAccessor(
|
||||
getter,
|
||||
|
||||
Reference in New Issue
Block a user