IrTypes: IrTypeParameter.superTypes can depend on type parameters

IrTypeParameter.superTypes can depend on type parameters and thus should
be initialized with type parameters in scope.
This commit is contained in:
Dmitry Petrov
2018-05-25 15:25:07 +03:00
parent eb6f652763
commit ad65fa8c45
7 changed files with 53 additions and 30 deletions
@@ -91,8 +91,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
startOffset,
endOffset,
IrDeclarationOrigin.DEFINED,
typeParameterDescriptor,
typeParameterDescriptor.upperBounds.map { it.toIrType() }
typeParameterDescriptor
)
}
}
@@ -106,8 +105,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
startOffset,
endOffset,
IrDeclarationOrigin.DEFINED,
typeParameterDescriptor,
typeParameterDescriptor.upperBounds.map { it.toIrType() }
typeParameterDescriptor
)
}
}
@@ -117,7 +115,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
from: List<TypeParameterDescriptor>,
declareTypeParameter: (Int, Int, TypeParameterDescriptor) -> IrTypeParameter
) {
val irTypeParameters = from.map { typeParameterDescriptor ->
from.mapTo(irTypeParametersOwner.typeParameters) { typeParameterDescriptor ->
val ktTypeParameterDeclaration = DescriptorToSourceUtils.getSourceFromDescriptor(typeParameterDescriptor)
val startOffset = ktTypeParameterDeclaration.startOffsetOrUndefined
val endOffset = ktTypeParameterDeclaration.endOffsetOrUndefined
@@ -128,7 +126,11 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
)
}
irTypeParametersOwner.typeParameters.addAll(irTypeParameters)
for (irTypeParameter in irTypeParametersOwner.typeParameters) {
irTypeParameter.descriptor.upperBounds.mapTo(irTypeParameter.superTypes) {
it.toIrType()
}
}
}
fun generateInitializerBody(scopeOwnerSymbol: IrSymbol, ktBody: KtExpression): IrExpressionBody =