From a377a6fccbea69566c7ce6fdce02c32482b5e701 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 31 Mar 2020 11:20:56 +0300 Subject: [PATCH] [FIR2IR] Handle references to constructors separately --- .../backend/generators/CallAndReferenceGenerator.kt | 10 ++++++++++ .../function/genericWithDependentType.kt | 1 - .../boundInnerGenericConstructor.fir.txt | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 8e90f162eaa..d1ef6c1cb3c 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrProperty import org.jetbrains.kotlin.ir.expressions.IrErrorCallExpression @@ -66,6 +67,15 @@ internal class CallAndReferenceGenerator( referencedProperty.setter?.symbol ) } + is IrConstructorSymbol -> { + val constructor = symbol.owner + val klass = constructor.parent as? IrClass + IrFunctionReferenceImpl( + startOffset, endOffset, type, symbol, + typeArgumentsCount = constructor.typeParameters.size + (klass?.typeParameters?.size ?: 0), + reflectionTarget = symbol + ) + } is IrFunctionSymbol -> { IrFunctionReferenceImpl( startOffset, endOffset, type, symbol, diff --git a/compiler/testData/codegen/box/callableReference/function/genericWithDependentType.kt b/compiler/testData/codegen/box/callableReference/function/genericWithDependentType.kt index abb0aa573dc..50ce78afc24 100644 --- a/compiler/testData/codegen/box/callableReference/function/genericWithDependentType.kt +++ b/compiler/testData/codegen/box/callableReference/function/genericWithDependentType.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME diff --git a/compiler/testData/ir/irText/expressions/callableReferences/boundInnerGenericConstructor.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/boundInnerGenericConstructor.fir.txt index 64dfab4b0a4..a844d62e69b 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/boundInnerGenericConstructor.fir.txt +++ b/compiler/testData/ir/irText/expressions/callableReferences/boundInnerGenericConstructor.fir.txt @@ -85,7 +85,9 @@ FILE fqName:test fileName:/boundInnerGenericConstructor.kt ERROR_CALL 'Unresolved reference: #' type=IrErrorType CONST String type=kotlin.String value="O" CONST String type=kotlin.String value="K" - ERROR_EXPR 'Cannot bind 1 type arguments to ??? call with 0 type parameters' type=kotlin.reflect.KFunction2> + FUNCTION_REFERENCE 'public constructor (a: T of test.Foo, b: P of test.Foo.Inner) [primary] declared in test.Foo.Inner' type=kotlin.reflect.KFunction2> origin=null reflectionTarget= +

: kotlin.Any? + $this: GET_VAR 'val z: test.Foo [val] declared in test.box' type=test.Foo origin=null RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in test' CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin' type=kotlin.String origin=PLUS $receiver: ERROR_CALL 'Unresolved reference: #' type=IrErrorType