Temporary disable line numbers generation for default values from expect declarations
Proper SMAP support for default values from expect declarations is required. Default value in expect declaration could has line number that exceed line count in actual file that causes an error #KT-23739 Fixed #KT-29174 Open
This commit is contained in:
@@ -89,6 +89,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isInt;
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
@@ -1432,12 +1433,14 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isShouldMarkLineNumbers() {
|
||||
return shouldMarkLineNumbers;
|
||||
}
|
||||
|
||||
public void setShouldMarkLineNumbers(boolean shouldMarkLineNumbers) {
|
||||
this.shouldMarkLineNumbers = shouldMarkLineNumbers;
|
||||
public <T> T runWithShouldMarkLineNumbers(boolean enable, Supplier<T> operation) {
|
||||
boolean originalStatus = shouldMarkLineNumbers;
|
||||
this.shouldMarkLineNumbers = enable;
|
||||
try {
|
||||
return operation.get();
|
||||
} finally {
|
||||
this.shouldMarkLineNumbers = originalStatus;
|
||||
}
|
||||
}
|
||||
|
||||
public void markStartLineNumber(@NotNull KtElement element) {
|
||||
|
||||
@@ -1313,8 +1313,14 @@ public class FunctionCodegen {
|
||||
Label loadArg = new Label();
|
||||
iv.ifeq(loadArg);
|
||||
|
||||
StackValue.local(parameterIndex, type, parameterDescriptor.getType())
|
||||
.store(loadStrategy.genValue(parameterDescriptor, codegen), iv);
|
||||
CallableDescriptor containingDeclaration = parameterDescriptor.getContainingDeclaration();
|
||||
codegen.runWithShouldMarkLineNumbers(
|
||||
!(containingDeclaration instanceof MemberDescriptor) || !((MemberDescriptor) containingDeclaration).isExpect(),
|
||||
() -> {
|
||||
StackValue.local(parameterIndex, type, parameterDescriptor.getType())
|
||||
.store(loadStrategy.genValue(parameterDescriptor, codegen), iv);
|
||||
return null;
|
||||
});
|
||||
|
||||
iv.mark(loadArg);
|
||||
}
|
||||
|
||||
@@ -323,30 +323,27 @@ fun FqName.topLevelClassInternalName() = JvmClassName.byClassId(ClassId(parent()
|
||||
fun FqName.topLevelClassAsmType(): Type = Type.getObjectType(topLevelClassInternalName())
|
||||
|
||||
fun initializeVariablesForDestructuredLambdaParameters(codegen: ExpressionCodegen, valueParameters: List<ValueParameterDescriptor>) {
|
||||
val savedIsShouldMarkLineNumbers = codegen.isShouldMarkLineNumbers
|
||||
// Do not write line numbers until destructuring happens
|
||||
// (otherwise destructuring variables will be uninitialized in the beginning of lambda)
|
||||
codegen.isShouldMarkLineNumbers = false
|
||||
codegen.runWithShouldMarkLineNumbers(false) {
|
||||
for (parameterDescriptor in valueParameters) {
|
||||
if (parameterDescriptor !is ValueParameterDescriptorImpl.WithDestructuringDeclaration) continue
|
||||
|
||||
for (parameterDescriptor in valueParameters) {
|
||||
if (parameterDescriptor !is ValueParameterDescriptorImpl.WithDestructuringDeclaration) continue
|
||||
for (entry in parameterDescriptor.destructuringVariables.filterOutDescriptorsWithSpecialNames()) {
|
||||
codegen.myFrameMap.enter(entry, codegen.typeMapper.mapType(entry.type))
|
||||
}
|
||||
|
||||
for (entry in parameterDescriptor.destructuringVariables.filterOutDescriptorsWithSpecialNames()) {
|
||||
codegen.myFrameMap.enter(entry, codegen.typeMapper.mapType(entry.type))
|
||||
val destructuringDeclaration =
|
||||
(DescriptorToSourceUtils.descriptorToDeclaration(parameterDescriptor) as? KtParameter)?.destructuringDeclaration
|
||||
?: error("Destructuring declaration for descriptor $parameterDescriptor not found")
|
||||
|
||||
codegen.initializeDestructuringDeclarationVariables(
|
||||
destructuringDeclaration,
|
||||
TransientReceiver(parameterDescriptor.type),
|
||||
codegen.findLocalOrCapturedValue(parameterDescriptor) ?: error("Local var not found for parameter $parameterDescriptor")
|
||||
)
|
||||
}
|
||||
|
||||
val destructuringDeclaration =
|
||||
(DescriptorToSourceUtils.descriptorToDeclaration(parameterDescriptor) as? KtParameter)?.destructuringDeclaration
|
||||
?: error("Destructuring declaration for descriptor $parameterDescriptor not found")
|
||||
|
||||
codegen.initializeDestructuringDeclarationVariables(
|
||||
destructuringDeclaration,
|
||||
TransientReceiver(parameterDescriptor.type),
|
||||
codegen.findLocalOrCapturedValue(parameterDescriptor) ?: error("Local var not found for parameter $parameterDescriptor")
|
||||
)
|
||||
}
|
||||
|
||||
codegen.isShouldMarkLineNumbers = savedIsShouldMarkLineNumbers
|
||||
}
|
||||
|
||||
fun <D : CallableDescriptor> D.unwrapFrontendVersion() = unwrapInitialDescriptorForSuspendFunction()
|
||||
|
||||
Reference in New Issue
Block a user