Write generic signature for closure FunctionN superclass

ClosureCodegen.appendType() now appends any Type as a type parameter correctly
This commit is contained in:
Alexander Udalov
2013-03-25 21:52:02 +04:00
parent 974df0ed8e
commit 0ec1f20140
3 changed files with 63 additions and 7 deletions
@@ -73,7 +73,7 @@ public class ClosureCodegen extends GenerationStateAware {
}
public ClosureCodegen gen(JetDeclarationWithBody fun, CodegenContext context, ExpressionCodegen expressionCodegen) {
name = classNameForAnonymousClass(state.getBindingContext(), fun);
name = classNameForAnonymousClass(bindingContext, fun);
ClassBuilder cv = state.getFactory().newVisitor(name.getInternalName(), fun.getContainingFile());
FunctionDescriptor funDescriptor = bindingContext.get(BindingContext.FUNCTION, fun);
@@ -89,10 +89,13 @@ public class ClosureCodegen extends GenerationStateAware {
SignatureWriter signatureWriter = new SignatureWriter();
List<ValueParameterDescriptor> parameters = funDescriptor.getValueParameters();
JvmClassName funClass = getInternalClassName(funDescriptor);
signatureWriter.visitClassType(funClass.getInternalName());
for (ValueParameterDescriptor parameter : parameters) {
ReceiverParameterDescriptor receiverParameter = funDescriptor.getReceiverParameter();
if (receiverParameter != null) {
appendType(signatureWriter, receiverParameter.getType(), '=');
}
for (ValueParameterDescriptor parameter : funDescriptor.getValueParameters()) {
appendType(signatureWriter, parameter.getType(), '=');
}
@@ -107,7 +110,7 @@ public class ClosureCodegen extends GenerationStateAware {
V1_6,
ACC_FINAL | ACC_SUPER,
name.getInternalName(),
null,
signatureWriter.toString(),
superclass.getInternalName(),
superInterfaces
);
@@ -123,7 +126,7 @@ public class ClosureCodegen extends GenerationStateAware {
generateConstInstance(fun, cv);
}
genClosureFields(closure, cv, state.getTypeMapper());
genClosureFields(closure, cv, typeMapper);
cv.done();
@@ -301,7 +304,17 @@ public class ClosureCodegen extends GenerationStateAware {
signatureWriter.visitTypeArgument(variance);
Type rawRetType = typeMapper.mapType(type, JetTypeMapperMode.TYPE_PARAMETER);
signatureWriter.visitClassType(rawRetType.getInternalName());
while (rawRetType.getSort() == Type.ARRAY) {
signatureWriter.visitArrayType();
rawRetType = rawRetType.getElementType();
}
if (rawRetType.getSort() == Type.OBJECT) {
signatureWriter.visitClassType(rawRetType.getInternalName());
}
else {
// rawRetType is primitive
signatureWriter.visitBaseType(rawRetType.getDescriptor().charAt(0));
}
signatureWriter.visitEnd();
}