generate local variables table for @JvmOverloads-generated methods

#KT-7319 Fixed
This commit is contained in:
Dmitry Jemerov
2016-02-01 18:45:41 +01:00
parent da7acd5e73
commit 970d6f6834
5 changed files with 43 additions and 5 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.jvm.diagnostics.OtherOrigin
import org.jetbrains.org.objectweb.asm.Label
import org.jetbrains.org.objectweb.asm.Opcodes
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
@@ -134,6 +135,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
}
if (state.classBuilderMode == ClassBuilderMode.LIGHT_CLASSES) {
FunctionCodegen.generateLocalVariablesForParameters(mv, signature, null, Label(), Label(), remainingParameters, isStatic)
mv.visitEnd()
return
}
@@ -142,6 +144,9 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
val v = InstructionAdapter(mv)
mv.visitCode()
val methodBegin = Label()
mv.visitLabel(methodBegin)
val methodOwner = typeMapper.mapToCallableMethod(delegateFunctionDescriptor, false).owner
if (!isStatic) {
val thisIndex = frameMap.enterTemp(AsmTypes.OBJECT_TYPE)
@@ -201,6 +206,13 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
v.invokestatic(methodOwner.internalName, defaultMethod.name, defaultMethod.descriptor, false)
}
v.areturn(signature.returnType)
val methodEnd = Label()
mv.visitLabel(methodEnd)
FunctionCodegen.generateLocalVariablesForParameters(mv, signature, null, methodBegin, methodEnd,
remainingParameters, isStatic)
FunctionCodegen.endVisit(mv, null, methodElement)
}
@@ -400,11 +400,24 @@ public class FunctionCodegen {
@NotNull Label methodEnd,
@NotNull OwnerKind ownerKind
) {
Iterator<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters().iterator();
generateLocalVariablesForParameters(mv, jvmMethodSignature, thisType, methodBegin, methodEnd,
functionDescriptor.getValueParameters(),
AsmUtil.isStaticMethod(ownerKind, functionDescriptor));
}
public static void generateLocalVariablesForParameters(
@NotNull MethodVisitor mv,
@NotNull JvmMethodSignature jvmMethodSignature,
@Nullable Type thisType,
@NotNull Label methodBegin,
@NotNull Label methodEnd,
Collection<ValueParameterDescriptor> valueParameters,
boolean isStatic
) {
Iterator<ValueParameterDescriptor> valueParameterIterator = valueParameters.iterator();
List<JvmMethodParameterSignature> params = jvmMethodSignature.getValueParameters();
int shift = 0;
boolean isStatic = AsmUtil.isStaticMethod(ownerKind, functionDescriptor);
if (!isStatic) {
//add this
if (thisType != null) {
@@ -422,7 +435,7 @@ public class FunctionCodegen {
String parameterName;
if (kind == JvmMethodParameterKind.VALUE) {
ValueParameterDescriptor parameter = valueParameters.next();
ValueParameterDescriptor parameter = valueParameterIterator.next();
parameterName = parameter.getName().asString();
}
else {