From aac940415f7d9934e8e1e61415b25085adeafba0 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Fri, 16 Mar 2018 12:22:56 +0300 Subject: [PATCH] Fix psi2ir when type parameter bound goes after the type parameter --- .../psi2ir/generators/DeclarationGenerator.kt | 12 ++-- .../parameters/typeParameterBeforeBound.kt | 7 +++ .../parameters/typeParameterBeforeBound.txt | 56 +++++++++++++++++++ .../kotlin/ir/IrTextTestCaseGenerated.java | 6 ++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt create mode 100644 compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.txt diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt index ad2b8533193..81998f9526e 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt @@ -108,7 +108,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator { from: List, declareTypeParameter: (Int, Int, TypeParameterDescriptor) -> IrTypeParameter ) { - from.mapTo(irTypeParametersOwner.typeParameters) { typeParameterDescriptor -> + val irTypeParameters = from.map { typeParameterDescriptor -> val ktTypeParameterDeclaration = DescriptorToSourceUtils.getSourceFromDescriptor(typeParameterDescriptor) val startOffset = ktTypeParameterDeclaration.startOffsetOrUndefined val endOffset = ktTypeParameterDeclaration.endOffsetOrUndefined @@ -116,10 +116,14 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator { startOffset, endOffset, typeParameterDescriptor - ).also { irTypeParameter -> - mapSuperClassifiers(typeParameterDescriptor, irTypeParameter) - } + ) } + + irTypeParameters.forEach { + mapSuperClassifiers(it.descriptor, it) + } + + irTypeParametersOwner.typeParameters.addAll(irTypeParameters) } private fun mapSuperClassifiers( diff --git a/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt new file mode 100644 index 00000000000..7c199dbbee9 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt @@ -0,0 +1,7 @@ +class Test1 + +fun test2() {} + +var Test1.test3: Unit + get() {} + set(value) {} diff --git a/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.txt b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.txt new file mode 100644 index 00000000000..6b24b647c4d --- /dev/null +++ b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.txt @@ -0,0 +1,56 @@ +FILE fqName: fileName:/typeParameterBeforeBound.kt + CLASS CLASS name:Test1 modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Test1 flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[U] + superClassifiers: + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + CONSTRUCTOR visibility:public <> () returnType:Test1 flags: + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='Test1' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:Boolean flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + VALUE_PARAMETER name:other index:0 type:kotlin.Any? flags: + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:Int flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + overridden: + FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:String flags: + $this: VALUE_PARAMETER name: type:kotlin.Any flags: + FUN name:test2 visibility:public modality:FINAL () returnType:Unit flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[U] + superClassifiers: + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + BLOCK_BODY + PROPERTY name:test3 type:kotlin.Unit visibility:public modality:FINAL flags:var + FUN name: visibility:public modality:FINAL ($receiver:Test1) returnType:Unit flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[U] + superClassifiers: + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + $receiver: VALUE_PARAMETER name: type:Test1 flags: + BLOCK_BODY + FUN name: visibility:public modality:FINAL ($receiver:Test1, value:kotlin.Unit) returnType:Unit flags: + TYPE_PARAMETER name:T index:0 variance: upperBounds:[U] + superClassifiers: + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + TYPE_PARAMETER name:U index:1 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + $receiver: VALUE_PARAMETER name: type:Test1 flags: + VALUE_PARAMETER name:value index:0 type:kotlin.Unit flags: + BLOCK_BODY diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 49500a1eb01..69001b0df9e 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -418,6 +418,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/parameters/propertyAccessors.kt"); doTest(fileName); } + + @TestMetadata("typeParameterBeforeBound.kt") + public void testTypeParameterBeforeBound() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/ir/irText/declarations/provideDelegate")