Put default value (null or zero) to slot for uninitialized values
This way range of the variable is correct in LVT. #KT-24672 Fixed
This commit is contained in:
@@ -4039,6 +4039,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
else if (property.hasModifier(KtTokens.LATEINIT_KEYWORD)) {
|
||||
initializeLocalVariable(property, null);
|
||||
}
|
||||
else if (!property.isVar()) {
|
||||
initializeLocalVariableWithFakeDefaultValue(property);
|
||||
}
|
||||
|
||||
return StackValue.none();
|
||||
}
|
||||
@@ -4182,6 +4185,47 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
storeTo.storeSelector(resultType, resultKotlinType, v);
|
||||
}
|
||||
|
||||
// This is a workaround to avoid bugs with incorrect range of uninitialized variable:
|
||||
// 1) JDI error 305
|
||||
// 2) Expected R, got . in code with contracts
|
||||
// 3) D8 dropping the whole LVT
|
||||
private void initializeLocalVariableWithFakeDefaultValue(@NotNull KtProperty variableDeclaration) {
|
||||
LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) getVariableDescriptorNotNull(variableDeclaration);
|
||||
|
||||
assert !variableDeclaration.isVar() && !variableDeclaration.hasDelegateExpressionOrInitializer() &&
|
||||
!variableDescriptor.isLateInit() : variableDeclaration.getText() + " in not variable declaration without initializer";
|
||||
|
||||
KotlinType kotlinType = variableDescriptor.getType();
|
||||
Type type = typeMapper.mapType(kotlinType);
|
||||
|
||||
if (type == Type.VOID_TYPE) return;
|
||||
|
||||
int index = lookupLocalIndex(variableDescriptor);
|
||||
assert index >= 0: variableDescriptor + " is not in frame map";
|
||||
|
||||
switch (type.getSort()) {
|
||||
case Type.BOOLEAN:
|
||||
case Type.CHAR:
|
||||
case Type.BYTE:
|
||||
case Type.SHORT:
|
||||
case Type.INT:
|
||||
v.iconst(0);
|
||||
break;
|
||||
case Type.FLOAT:
|
||||
v.fconst(0.0f);
|
||||
break;
|
||||
case Type.LONG:
|
||||
v.lconst(0L);
|
||||
break;
|
||||
case Type.DOUBLE:
|
||||
v.dconst(0.0);
|
||||
break;
|
||||
default:
|
||||
v.aconst(null);
|
||||
}
|
||||
v.store(index, type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private StackValue generateProvideDelegateCallForLocalVariable(
|
||||
@NotNull StackValue initializer,
|
||||
|
||||
Reference in New Issue
Block a user