From ecd2709a113c0d95536baa043c0c8ca896230366 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 18 Jun 2018 14:06:44 +0300 Subject: [PATCH] psi2ir: type arguments for function references --- .../ReflectionReferencesGenerator.kt | 4 +- .../kotlin/ir/util/DeepCopyIrTree.kt | 2 +- .../callableReferenceTypeArguments.kt | 14 ++++ .../callableReferenceTypeArguments.txt | 72 +++++++++++++++++++ .../kotlin/ir/IrTextTestCaseGenerated.java | 5 ++ 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.kt create mode 100644 compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.txt diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt index 69ab8bbffca..6c3f1eb877a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt @@ -72,7 +72,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St startOffset, endOffset, getInferredTypeWithImplicitCastsOrFail(ktCallableReference), referencedDescriptor, - typeArguments = null + resolvedCall.typeArguments ).also { irCallableReference -> irCallableReference.dispatchReceiver = dispatchReceiverValue?.loadIfExists() irCallableReference.extensionReceiver = extensionReceiverValue?.loadIfExists() @@ -150,7 +150,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St ) } - fun generateFunctionReference( + private fun generateFunctionReference( startOffset: Int, endOffset: Int, type: KotlinType, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt index 6b1ce661217..7ba06908134 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt @@ -482,7 +482,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { return IrFunctionReferenceImpl( expression.startOffset, expression.endOffset, expression.type, - newCallee.original, + newCallee, expression.typeArgumentsCount, mapStatementOrigin(expression.origin) ).apply { diff --git a/compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.kt b/compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.kt new file mode 100644 index 00000000000..4394fbc63c2 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.kt @@ -0,0 +1,14 @@ +import Host.objectMember + +object Host { + inline fun objectMember(x: T) {} +} + +inline fun topLevel1(x: T) {} +inline fun topLevel2(x: List) {} + +val test1: (Int) -> Unit = ::topLevel1 + +val test2: (List) -> Unit = ::topLevel2 + +val test3: (Int) -> Unit = ::objectMember diff --git a/compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.txt b/compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.txt new file mode 100644 index 00000000000..57e804ccdad --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.txt @@ -0,0 +1,72 @@ +FILE fqName: fileName:/callableReferenceTypeArguments.kt + CLASS OBJECT name:Host modality:FINAL visibility:public flags: + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:Host flags: + superClasses: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + CONSTRUCTOR visibility:private <> () returnType:Host flags:primary + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='Host' + FUN name:objectMember visibility:public modality:FINAL ($this:Host, x:T) returnType:Unit flags:inline + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + $this: VALUE_PARAMETER name: type:Host flags: + VALUE_PARAMETER name:x index:0 type:T flags: + BLOCK_BODY + 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:topLevel1 visibility:public modality:FINAL (x:T) returnType:Unit flags:inline + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + VALUE_PARAMETER name:x index:0 type:T flags: + BLOCK_BODY + FUN name:topLevel2 visibility:public modality:FINAL (x:kotlin.collections.List) returnType:Unit flags:inline + TYPE_PARAMETER name:T index:0 variance: upperBounds:[kotlin.Any?] + superClassifiers: + CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:Any modality:OPEN visibility:public flags: + VALUE_PARAMETER name:x index:0 type:kotlin.collections.List flags: + BLOCK_BODY + PROPERTY name:test1 type:(kotlin.Int) -> kotlin.Unit visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:test1 type:(kotlin.Int) -> kotlin.Unit visibility:public flags:final + EXPRESSION_BODY + FUNCTION_REFERENCE 'topLevel1(Int): Unit' type=kotlin.reflect.KFunction1<@kotlin.ParameterName kotlin.Int, kotlin.Unit> origin=null + : Int + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:Function1 flags: + correspondingProperty: PROPERTY name:test1 type:(kotlin.Int) -> kotlin.Unit visibility:public modality:FINAL flags:val + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): (Int) -> Unit' + GET_FIELD 'test1: (Int) -> Unit' type=(kotlin.Int) -> kotlin.Unit origin=null + PROPERTY name:test2 type:(kotlin.collections.List) -> kotlin.Unit visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:test2 type:(kotlin.collections.List) -> kotlin.Unit visibility:public flags:final + EXPRESSION_BODY + FUNCTION_REFERENCE 'topLevel2(List): Unit' type=kotlin.reflect.KFunction1<@kotlin.ParameterName kotlin.collections.List, kotlin.Unit> origin=null + : String + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:Function1, Unit> flags: + correspondingProperty: PROPERTY name:test2 type:(kotlin.collections.List) -> kotlin.Unit visibility:public modality:FINAL flags:val + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): (List) -> Unit' + GET_FIELD 'test2: (List) -> Unit' type=(kotlin.collections.List) -> kotlin.Unit origin=null + PROPERTY name:test3 type:(kotlin.Int) -> kotlin.Unit visibility:public modality:FINAL flags:val + FIELD PROPERTY_BACKING_FIELD name:test3 type:(kotlin.Int) -> kotlin.Unit visibility:public flags:final + EXPRESSION_BODY + FUNCTION_REFERENCE 'objectMember(Int): Unit' type=kotlin.reflect.KFunction1<@kotlin.ParameterName kotlin.Int, kotlin.Unit> origin=null + : Int + $this: GET_OBJECT 'Host' type=Host + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:Function1 flags: + correspondingProperty: PROPERTY name:test3 type:(kotlin.Int) -> kotlin.Unit visibility:public modality:FINAL flags:val + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): (Int) -> Unit' + GET_FIELD 'test3: (Int) -> Unit' type=(kotlin.Int) -> kotlin.Unit origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 1f95e6ebb46..adeccf3e709 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -737,6 +737,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferenceToImportedFromObject.kt"); } + @TestMetadata("callableReferenceTypeArguments.kt") + public void testCallableReferenceTypeArguments() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferenceTypeArguments.kt"); + } + @TestMetadata("calls.kt") public void testCalls() throws Exception { runTest("compiler/testData/ir/irText/expressions/calls.kt");