DefaultImpls fixes

This commit is contained in:
Michael Bogdanov
2016-10-01 14:15:36 +03:00
committed by Dmitry Petrov
parent c22bfaeefb
commit bc6f691405
2 changed files with 11 additions and 8 deletions
@@ -79,7 +79,7 @@ class InterfaceDelegationLowering(val state: GenerationState) : IrElementTransfo
var shift = 0
if (inheritedFun.dispatchReceiverParameter != null) {
irCallImpl.putValueArgument(0, IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irClass.descriptor.thisAsReceiverParameter))
irCallImpl.putValueArgument(0, IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, interfaceFun.dispatchReceiverParameter!!))
shift = 1
}
inheritedFun.valueParameters.mapIndexed { i, valueParameterDescriptor ->
@@ -66,7 +66,8 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid()
members.add(newFunction)
it.body = null
val mapping: Map<DeclarationDescriptor, ValueParameterDescriptor> = (listOf(it.descriptor.containingDeclaration) + it.descriptor.valueParameters).zip(functionDescriptorImpl.valueParameters).toMap()
val mapping: Map<DeclarationDescriptor, ValueParameterDescriptor> =
(listOf(it.descriptor.dispatchReceiverParameter!!) + it.descriptor.valueParameters).zip(functionDescriptorImpl.valueParameters).toMap()
newFunction.body?.transform(VariableRemapper(mapping), null)
}
@@ -100,12 +101,14 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid()
CallableMemberDescriptor.Kind.DECLARATION, descriptor.source
)
val valueParameters =
listOf(ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
newFunction, null, 0, AnnotationsImpl(emptyList()), Name.identifier("this"),
interfaceDescriptor.defaultType, false, false, false, false, null, interfaceDescriptor.source, null)
) +
descriptor.valueParameters.map { it.copy(newFunction, it.name, it.index + 1) }
val dispatchReceiver =
ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
newFunction, null, 0, AnnotationsImpl(emptyList()), Name.identifier("this"),
interfaceDescriptor.defaultType, false, false, false, false, null, interfaceDescriptor.source, null)
val valueParameters = listOf(dispatchReceiver) +
descriptor.valueParameters.map { it.copy(newFunction, it.name, it.index + 1) }
newFunction.initialize(
null, null, emptyList()/*TODO: type parameters*/,
valueParameters, descriptor.returnType, Modality.FINAL, descriptor.visibility