IrTypes: IrClass.superTypes can depend on type parameters

IrClass.superTypes can depend on type parameters of a class and thus
should be initialized after type parameters are in put in scope.
This commit is contained in:
Dmitry Petrov
2018-05-25 15:04:11 +03:00
parent 8ae17ecbcb
commit eb6f652763
3 changed files with 5 additions and 4 deletions
@@ -54,6 +54,8 @@ class ClassGenerator(
return context.symbolTable.declareClass(
startOffset, endOffset, IrDeclarationOrigin.DEFINED, classDescriptor
).buildWithScope { irClass ->
declarationGenerator.generateGlobalTypeParametersDeclarations(irClass, classDescriptor.declaredTypeParameters)
classDescriptor.typeConstructor.supertypes.mapTo(irClass.superTypes) {
it.toIrType()
}
@@ -65,8 +67,6 @@ class ClassGenerator(
classDescriptor.thisAsReceiverParameter.type.toIrType()
)
declarationGenerator.generateGlobalTypeParametersDeclarations(irClass, classDescriptor.declaredTypeParameters)
val irPrimaryConstructor = generatePrimaryConstructor(irClass, ktClassOrObject)
if (irPrimaryConstructor != null) {
generateDeclarationsForPrimaryConstructorParameters(irClass, irPrimaryConstructor, ktClassOrObject)
@@ -138,12 +138,13 @@ class DeclarationStubGenerator(
private fun generateClassStub(descriptor: ClassDescriptor): IrClass =
symbolTable.declareClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor).also { irClass ->
generateTypeParameterStubs(descriptor.declaredTypeParameters, irClass)
// TODO get rid of code duplication, see ClassGenerator#generateClass
descriptor.typeConstructor.supertypes.mapNotNullTo(irClass.superTypes) {
it.toIrType()
}
generateTypeParameterStubs(descriptor.declaredTypeParameters, irClass)
irClass.thisReceiver = descriptor.thisAsReceiverParameter.generateReceiverParameterStub()
generateChildStubs(descriptor.constructors, irClass)
generateMemberStubs(descriptor.defaultType.memberScope, irClass)
@@ -99,11 +99,11 @@ open class DeepCopyIrTreeWithSymbols(
symbolRemapper.getDeclaredClass(declaration.symbol)
).apply {
transformAnnotations(declaration)
declaration.typeParameters.transformTo(typeParameters)
declaration.superTypes.mapTo(superTypes) {
it.remapType()
}
thisReceiver = declaration.thisReceiver?.transform()
declaration.typeParameters.transformTo(typeParameters)
declaration.transformDeclarationsTo(this)
}