diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt index 1fe2adcacf9..64bebc2ced1 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.IrTypeParameter import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator +import org.jetbrains.kotlin.ir.util.withScope import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal @@ -55,7 +56,17 @@ class IrLazyConstructor( TypeTranslator ) - override val typeParameters: MutableList = arrayListOf() + override val typeParameters: MutableList by lazy { + typeTranslator.buildWithScope(this) { + stubGenerator.symbolTable.withScope(descriptor) { + val classTypeParametersCount = descriptor.constructedClass.original.declaredTypeParameters.size + val allConstructorTypeParameters = descriptor.typeParameters + allConstructorTypeParameters.subList(classTypeParametersCount, allConstructorTypeParameters.size).mapTo(ArrayList()) { + stubGenerator.generateOrGetTypeParameterStub(it) + } + } + } + } init { symbol.bind(this) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt index a49262821f2..172353eaa09 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator +import org.jetbrains.kotlin.ir.util.withScope import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor @@ -62,18 +63,17 @@ class IrLazyFunction( override val typeParameters: MutableList by lazy { typeTranslator.buildWithScope(this) { - stubGenerator.symbolTable.enterScope(descriptor) - val propertyIfAccessor = descriptor.propertyIfAccessor - propertyIfAccessor.typeParameters.mapTo(arrayListOf()) { - if (descriptor != propertyIfAccessor) { - stubGenerator.generateOrGetScopedTypeParameterStub(it).also { - it.parent = this@IrLazyFunction + stubGenerator.symbolTable.withScope(descriptor) { + val propertyIfAccessor = descriptor.propertyIfAccessor + propertyIfAccessor.typeParameters.mapTo(arrayListOf()) { + if (descriptor != propertyIfAccessor) { + stubGenerator.generateOrGetScopedTypeParameterStub(it).also { + it.parent = this@IrLazyFunction + } + } else { + stubGenerator.generateOrGetTypeParameterStub(it) } - } else { - stubGenerator.generateOrGetTypeParameterStub(it) } - }.also { - stubGenerator.symbolTable.leaveScope(descriptor) } } } diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.kt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.kt new file mode 100644 index 00000000000..d0895d2e74d --- /dev/null +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.kt @@ -0,0 +1,8 @@ +// FILE: javaConstructorWithTypeParameters.kt +// DUMP_EXTERNAL_CLASS J +fun test() = J() + +// FILE: J.java +public class J { + public J() {} +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.txt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.txt new file mode 100644 index 00000000000..939eb4c6955 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.txt @@ -0,0 +1,6 @@ +FILE fqName: fileName:/javaConstructorWithTypeParameters.kt + FUN name:test visibility:public modality:FINAL <> () returnType:.J + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test (): .J declared in ' + CALL 'public constructor () declared in .J' type=.J origin=null + : kotlin.String diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters__J.txt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters__J.txt new file mode 100644 index 00000000000..d3d9b399c98 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters__J.txt @@ -0,0 +1,17 @@ +CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:J modality:OPEN visibility:public superTypes:[] + $this: VALUE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name: type:.J + CONSTRUCTOR IR_EXTERNAL_DECLARATION_STUB visibility:public () returnType:.J + TYPE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name:T index:0 variance: superTypes:[?] + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:) returnType: + overridden: + public open fun hashCode (): declared in kotlin.Any + $this: VALUE_PARAMETER FAKE_OVERRIDE name: type:kotlin.Any + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType: + overridden: + public open fun equals (other: kotlin.Any?): declared in kotlin.Any + $this: VALUE_PARAMETER FAKE_OVERRIDE name: type:kotlin.Any + VALUE_PARAMETER IR_EXTERNAL_DECLARATION_STUB name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType: + overridden: + public open fun toString (): declared in kotlin.Any + $this: VALUE_PARAMETER FAKE_OVERRIDE name: type:kotlin.Any diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index a3a75312de9..d0b178c58cc 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1518,6 +1518,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/stubs/genericClassInDifferentModule.kt"); } + @TestMetadata("javaConstructorWithTypeParameters.kt") + public void testJavaConstructorWithTypeParameters() throws Exception { + runTest("compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.kt"); + } + @TestMetadata("javaEnum.kt") public void testJavaEnum() throws Exception { runTest("compiler/testData/ir/irText/stubs/javaEnum.kt");