diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 4f52a8e1307..697c25f4c10 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -1829,6 +1829,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt"); } + @Test + @TestMetadata("kt46069.kt") + public void testKt46069() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/kt46069.kt"); + } + @Test @TestMetadata("suspendConversion.kt") public void testSuspendConversion() throws Exception { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt index 5065cc7291c..3c790483f43 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.IrConstructor import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer +import org.jetbrains.kotlin.ir.descriptors.IrBasedTypeParameterDescriptor import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol @@ -74,6 +75,9 @@ abstract class TypeTranslator( } private fun resolveTypeParameter(typeParameterDescriptor: TypeParameterDescriptor): IrTypeParameterSymbol { + if (typeParameterDescriptor is IrBasedTypeParameterDescriptor) { + return typeParameterDescriptor.owner.symbol + } val originalTypeParameter = typeParameterDescriptor.originalTypeParameter return typeParametersResolver.resolveScopedTypeParameter(originalTypeParameter) ?: symbolTable.referenceTypeParameter(originalTypeParameter) diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt46069.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/kt46069.fir.txt new file mode 100644 index 00000000000..d57d677477f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt46069.fir.txt @@ -0,0 +1,94 @@ +FILE fqName: fileName:/kt46069.kt + CLASS CLASS name:ObjectAssert modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.ObjectAssert.ObjectAssert> + TYPE_PARAMETER name:ACTUAL index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.ObjectAssert.ObjectAssert> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ObjectAssert modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:describedAs visibility:public modality:FINAL <> ($this:.ObjectAssert.ObjectAssert>, description:kotlin.String?, args:kotlin.Array) returnType:.ObjectAssert.ObjectAssert>? + $this: VALUE_PARAMETER name: type:.ObjectAssert.ObjectAssert> + VALUE_PARAMETER name:description index:0 type:kotlin.String? + VALUE_PARAMETER name:args index:1 type:kotlin.Array varargElementType:kotlin.Any? [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun describedAs (description: kotlin.String?, vararg args: kotlin.Any?): .ObjectAssert.ObjectAssert>? declared in .ObjectAssert' + CONST Null type=kotlin.Nothing? value=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:Assertions modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Assertions + CONSTRUCTOR visibility:private <> () returnType:.Assertions [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Assertions modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:assertThat visibility:public modality:FINAL ($this:.Assertions, actual:S of .Assertions.assertThat) returnType:.ObjectAssert.Assertions.assertThat> + TYPE_PARAMETER name:S index:0 variance: superTypes:[kotlin.Any?] + $this: VALUE_PARAMETER name: type:.Assertions + VALUE_PARAMETER name:actual index:0 type:S of .Assertions.assertThat + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun assertThat (actual: S of .Assertions.assertThat): .ObjectAssert.Assertions.assertThat> declared in .Assertions' + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .ObjectAssert' type=.ObjectAssert.Assertions.assertThat> origin=null + : S of .Assertions.assertThat + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:assertNotNull visibility:public modality:FINAL ($receiver:T of .assertNotNull?, description:kotlin.String?) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] + $receiver: VALUE_PARAMETER name: type:T of .assertNotNull? + VALUE_PARAMETER name:description index:0 type:kotlin.String? + EXPRESSION_BODY + CONST Null type=kotlin.Nothing? value=null + BLOCK_BODY + VAR name:assert type:.ObjectAssert.assertNotNull?> [val] + CALL 'public final fun assertThat (actual: S of .Assertions.assertThat): .ObjectAssert.Assertions.assertThat> declared in .Assertions' type=.ObjectAssert.assertNotNull?> origin=null + : T of .assertNotNull? + $this: GET_OBJECT 'CLASS OBJECT name:Assertions modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Assertions + actual: GET_VAR ': T of .assertNotNull? declared in .assertNotNull' type=T of .assertNotNull? origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + BLOCK type=.ObjectAssert.assertNotNull?>? origin=SAFE_CALL + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.String? [val] + GET_VAR 'description: kotlin.String? declared in .assertNotNull' type=kotlin.String? origin=null + WHEN type=.ObjectAssert.assertNotNull?>? origin=null + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val tmp_0: kotlin.String? [val] declared in .assertNotNull' type=kotlin.String? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Null type=kotlin.Nothing? value=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public final fun let (block: kotlin.Function1): R of kotlin.StandardKt.let [inline] declared in kotlin.StandardKt' type=.ObjectAssert.assertNotNull?>? origin=null + : kotlin.String + : .ObjectAssert.assertNotNull?>? + $receiver: GET_VAR 'val tmp_0: kotlin.String? [val] declared in .assertNotNull' type=kotlin.String? origin=null + block: BLOCK type=kotlin.Function1.ObjectAssert.assertNotNull?>?> origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:describedAs visibility:local modality:FINAL <> ($receiver:.ObjectAssert.assertNotNull?>, p0:kotlin.String?) returnType:.ObjectAssert.assertNotNull?>? + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.ObjectAssert.assertNotNull?> + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String? + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun describedAs (p0: kotlin.String?): .ObjectAssert.assertNotNull?>? declared in .assertNotNull' + CALL 'public final fun describedAs (description: kotlin.String?, vararg args: kotlin.Any?): .ObjectAssert.ObjectAssert>? declared in .ObjectAssert' type=.ObjectAssert.ObjectAssert>? origin=null + $this: GET_VAR 'receiver: .ObjectAssert.assertNotNull?> declared in .assertNotNull.describedAs' type=.ObjectAssert.assertNotNull?> origin=ADAPTED_FUNCTION_REFERENCE + description: GET_VAR 'p0: kotlin.String? declared in .assertNotNull.describedAs' type=kotlin.String? origin=null + FUNCTION_REFERENCE 'local final fun describedAs (p0: kotlin.String?): .ObjectAssert.assertNotNull?>? declared in .assertNotNull' type=kotlin.Function1.ObjectAssert.assertNotNull?>?> origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=null + $receiver: GET_VAR 'val assert: .ObjectAssert.assertNotNull?> [val] declared in .assertNotNull' type=.ObjectAssert.assertNotNull?> origin=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt46069.kt b/compiler/testData/ir/irText/expressions/callableReferences/kt46069.kt new file mode 100644 index 00000000000..c10c36f0f4b --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt46069.kt @@ -0,0 +1,14 @@ +// SKIP_KT_DUMP + +class ObjectAssert { + fun describedAs(description: String?, vararg args: Any?): ObjectAssert? = null +} + +object Assertions { + fun assertThat(actual: S): ObjectAssert = ObjectAssert() +} + +fun T?.assertNotNull(description: String? = null) { + val assert = Assertions.assertThat(this) + description?.let(assert::describedAs) +} diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt46069.txt b/compiler/testData/ir/irText/expressions/callableReferences/kt46069.txt new file mode 100644 index 00000000000..6aea5711d27 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt46069.txt @@ -0,0 +1,96 @@ +FILE fqName: fileName:/kt46069.kt + CLASS CLASS name:ObjectAssert modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.ObjectAssert.ObjectAssert> + TYPE_PARAMETER name:ACTUAL index:0 variance: superTypes:[kotlin.Any?] + CONSTRUCTOR visibility:public <> () returnType:.ObjectAssert.ObjectAssert> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ObjectAssert modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:describedAs visibility:public modality:FINAL <> ($this:.ObjectAssert.ObjectAssert>, description:kotlin.String?, args:kotlin.Array) returnType:.ObjectAssert.ObjectAssert>? + $this: VALUE_PARAMETER name: type:.ObjectAssert.ObjectAssert> + VALUE_PARAMETER name:description index:0 type:kotlin.String? + VALUE_PARAMETER name:args index:1 type:kotlin.Array varargElementType:kotlin.Any? [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun describedAs (description: kotlin.String?, vararg args: kotlin.Any?): .ObjectAssert.ObjectAssert>? declared in .ObjectAssert' + CONST Null type=kotlin.Nothing? value=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:Assertions modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Assertions + CONSTRUCTOR visibility:private <> () returnType:.Assertions [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Assertions modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:assertThat visibility:public modality:FINAL ($this:.Assertions, actual:S of .Assertions.assertThat) returnType:.ObjectAssert.Assertions.assertThat> + TYPE_PARAMETER name:S index:0 variance: superTypes:[kotlin.Any?] + $this: VALUE_PARAMETER name: type:.Assertions + VALUE_PARAMETER name:actual index:0 type:S of .Assertions.assertThat + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun assertThat (actual: S of .Assertions.assertThat): .ObjectAssert.Assertions.assertThat> declared in .Assertions' + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .ObjectAssert' type=.ObjectAssert.Assertions.assertThat> origin=null + : S of .Assertions.assertThat + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:assertNotNull visibility:public modality:FINAL ($receiver:T of .assertNotNull?, description:kotlin.String?) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] + $receiver: VALUE_PARAMETER name: type:T of .assertNotNull? + VALUE_PARAMETER name:description index:0 type:kotlin.String? + EXPRESSION_BODY + CONST Null type=kotlin.Nothing? value=null + BLOCK_BODY + VAR name:assert type:.ObjectAssert.assertNotNull?> [val] + CALL 'public final fun assertThat (actual: S of .Assertions.assertThat): .ObjectAssert.Assertions.assertThat> declared in .Assertions' type=.ObjectAssert.assertNotNull?> origin=null + : T of .assertNotNull? + $this: GET_OBJECT 'CLASS OBJECT name:Assertions modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Assertions + actual: GET_VAR ': T of .assertNotNull? declared in .assertNotNull' type=T of .assertNotNull? origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + BLOCK type=.ObjectAssert.assertNotNull?>? origin=SAFE_CALL + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.String? [val] + GET_VAR 'description: kotlin.String? declared in .assertNotNull' type=kotlin.String? origin=null + WHEN type=.ObjectAssert.assertNotNull?>? origin=null + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val tmp_0: kotlin.String? [val] declared in .assertNotNull' type=kotlin.String? origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + then: CONST Null type=kotlin.Nothing? value=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CALL 'public final fun let (block: kotlin.Function1): R of kotlin.StandardKt.let [inline] declared in kotlin.StandardKt' type=.ObjectAssert.assertNotNull?>? origin=null + : kotlin.String + : .ObjectAssert.assertNotNull?>? + $receiver: GET_VAR 'val tmp_0: kotlin.String? [val] declared in .assertNotNull' type=kotlin.String? origin=null + block: BLOCK type=kotlin.Function1.ObjectAssert.assertNotNull?>?> origin=ADAPTED_FUNCTION_REFERENCE + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:describedAs visibility:local modality:FINAL <> ($receiver:.ObjectAssert.assertNotNull?>, p0:kotlin.String?) returnType:.ObjectAssert.assertNotNull?>? + $receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:.ObjectAssert.assertNotNull?> + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String? + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun describedAs (p0: kotlin.String?): .ObjectAssert.assertNotNull?>? declared in .assertNotNull' + TYPE_OP type=.ObjectAssert.assertNotNull>? origin=IMPLICIT_CAST typeOperand=.ObjectAssert.assertNotNull>? + CALL 'public final fun describedAs (description: kotlin.String?, vararg args: kotlin.Any?): .ObjectAssert.ObjectAssert>? declared in .ObjectAssert' type=.ObjectAssert.assertNotNull?>? origin=null + $this: GET_VAR 'receiver: .ObjectAssert.assertNotNull?> declared in .assertNotNull.describedAs' type=.ObjectAssert.assertNotNull?> origin=ADAPTED_FUNCTION_REFERENCE + description: GET_VAR 'p0: kotlin.String? declared in .assertNotNull.describedAs' type=kotlin.String? origin=null + FUNCTION_REFERENCE 'local final fun describedAs (p0: kotlin.String?): .ObjectAssert.assertNotNull?>? declared in .assertNotNull' type=kotlin.Function1.ObjectAssert.assertNotNull?>?> origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=public final fun describedAs (description: kotlin.String?, vararg args: kotlin.Any?): .ObjectAssert.ObjectAssert>? declared in .ObjectAssert + $receiver: TYPE_OP type=.ObjectAssert.assertNotNull> origin=IMPLICIT_CAST typeOperand=.ObjectAssert.assertNotNull> + GET_VAR 'val assert: .ObjectAssert.assertNotNull?> [val] declared in .assertNotNull' type=.ObjectAssert.assertNotNull?> origin=null diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index af1d4293eb6..1b5559bbfbf 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -1829,6 +1829,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt"); } + @Test + @TestMetadata("kt46069.kt") + public void testKt46069() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/kt46069.kt"); + } + @Test @TestMetadata("suspendConversion.kt") public void testSuspendConversion() throws Exception {