From 4038c758ca554e232300d88f2c72f50850d527cf Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 5 Mar 2020 16:37:51 +0300 Subject: [PATCH] KT-37131 Record default arguments in argument adaptation Also, don't adapt argument when expected type is base reflection type (KCallable, etc), since such types don't contain parameter types. --- .../kotlin/fir/Fir2IrTextTestGenerated.java | 10 +++ .../components/CallableReferenceResolution.kt | 14 +++- ...thDefaultParametersAsKCallableStar.fir.txt | 73 +++++++++++++++++++ ...funWithDefaultParametersAsKCallableStar.kt | 21 ++++++ ...unWithDefaultParametersAsKCallableStar.txt | 73 +++++++++++++++++++ .../callableReferences/kt37131.fir.txt | 57 +++++++++++++++ .../expressions/callableReferences/kt37131.kt | 9 +++ .../callableReferences/kt37131.txt | 67 +++++++++++++++++ .../kotlin/ir/IrTextTestCaseGenerated.java | 10 +++ 9 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.fir.txt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.kt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.txt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/kt37131.fir.txt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt create mode 100644 compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index 17eae18577f..2e7264b7385 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1379,6 +1379,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.kt"); } + @TestMetadata("funWithDefaultParametersAsKCallableStar.kt") + public void testFunWithDefaultParametersAsKCallableStar() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.kt"); + } + @TestMetadata("genericMember.kt") public void testGenericMember() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/genericMember.kt"); @@ -1389,6 +1394,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/importedFromObject.kt"); } + @TestMetadata("kt37131.kt") + public void testKt37131() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt"); + } + @TestMetadata("typeArguments.kt") public void testTypeArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/typeArguments.kt"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 6fdcc4b6895..c5ef19b3351 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -304,7 +304,10 @@ class CallableReferencesCandidateFactory( mappedArgumentTypes[index] = mappedArgument } - if (resolvedArgument == ResolvedCallArgument.DefaultArgument) defaults++ + if (resolvedArgument == ResolvedCallArgument.DefaultArgument) { + defaults++ + mappedArguments[valueParameter] = resolvedArgument + } } if (mappedArgumentTypes.any { it == null }) return null @@ -317,9 +320,16 @@ class CallableReferencesCandidateFactory( val coercion = if (returnExpectedType.isUnit()) CoercionStrategy.COERCION_TO_UNIT else CoercionStrategy.NO_COERCION + val adaptedArguments = + if (expectedType != null && ReflectionTypes.isBaseTypeForNumberedReferenceTypes(expectedType)) + emptyMap() + else + mappedArguments + return CallableReferenceAdaptation( @Suppress("UNCHECKED_CAST") (mappedArgumentTypes as Array), - coercion, defaults, mappedArguments + coercion, defaults, + adaptedArguments ) } diff --git a/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.fir.txt new file mode 100644 index 00000000000..ed1126616f3 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.fir.txt @@ -0,0 +1,73 @@ +FILE fqName: fileName:/funWithDefaultParametersAsKCallableStar.kt + FUN name:defaultsOnly visibility:public modality:FINAL <> (x:kotlin.String) returnType:kotlin.Int + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun defaultsOnly (x: kotlin.String): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:regularAndDefaults visibility:public modality:FINAL <> (x1:kotlin.String, x2:kotlin.String) returnType:kotlin.Int + VALUE_PARAMETER name:x1 index:0 type:kotlin.String + VALUE_PARAMETER name:x2 index:1 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun regularAndDefaults (x1: kotlin.String, x2: kotlin.String): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:varargs visibility:public modality:FINAL <> (xs:kotlin.Array) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.Array varargElementType:kotlin.String [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun varargs (vararg xs: kotlin.String): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> (x:kotlin.String) returnType:.C [primary] + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:x visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'x: kotlin.String declared in .C.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.String + correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .C' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .C declared in .C.' type=.C origin=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 + FUN name:useKCallableStar visibility:public modality:FINAL <> (fn:kotlin.reflect.KCallable<*>) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.reflect.KCallable<*> + BLOCK_BODY + FUN name:testDefaultsOnlyStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun defaultsOnly (x: kotlin.String): kotlin.Int declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testRegularAndDefaultsStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun regularAndDefaults (x1: kotlin.String, x2: kotlin.String): kotlin.Int declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= + FUN name:testVarargsStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun varargs (vararg xs: kotlin.String): kotlin.Int declared in ' type=kotlin.reflect.KFunction1, kotlin.Int> origin=null reflectionTarget= + FUN name:testCtorStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public constructor (x: kotlin.String) [primary] declared in .C' type=kotlin.reflect.KFunction0<.C> origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.kt b/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.kt new file mode 100644 index 00000000000..5455d83efa3 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.kt @@ -0,0 +1,21 @@ +// WITH_REFLECT +import kotlin.reflect.KCallable + +fun defaultsOnly(x: String = "") = 1 + +fun regularAndDefaults(x1: String, x2: String = "") = 1 + +fun varargs(vararg xs: String) = 1 + +class C(val x: String = "") + +fun useKCallableStar(fn: KCallable<*>) {} + + +fun testDefaultsOnlyStar() { useKCallableStar(::defaultsOnly) } + +fun testRegularAndDefaultsStar() { useKCallableStar(::regularAndDefaults) } + +fun testVarargsStar() { useKCallableStar(::varargs) } + +fun testCtorStar() { useKCallableStar(::C) } diff --git a/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.txt b/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.txt new file mode 100644 index 00000000000..e77faa1b419 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.txt @@ -0,0 +1,73 @@ +FILE fqName: fileName:/funWithDefaultParametersAsKCallableStar.kt + FUN name:defaultsOnly visibility:public modality:FINAL <> (x:kotlin.String) returnType:kotlin.Int + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun defaultsOnly (x: kotlin.String): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:regularAndDefaults visibility:public modality:FINAL <> (x1:kotlin.String, x2:kotlin.String) returnType:kotlin.Int + VALUE_PARAMETER name:x1 index:0 type:kotlin.String + VALUE_PARAMETER name:x2 index:1 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun regularAndDefaults (x1: kotlin.String, x2: kotlin.String): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:varargs visibility:public modality:FINAL <> (xs:kotlin.Array) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.Array varargElementType:kotlin.String [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun varargs (vararg xs: kotlin.String): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=1 + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> (x:kotlin.String) returnType:.C [primary] + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:x visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'x: kotlin.String declared in .C.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.String + correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .C' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .C declared in .C.' type=.C origin=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 + FUN name:useKCallableStar visibility:public modality:FINAL <> (fn:kotlin.reflect.KCallable<*>) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.reflect.KCallable<*> + BLOCK_BODY + FUN name:testDefaultsOnlyStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun defaultsOnly (x: kotlin.String): kotlin.Int declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testRegularAndDefaultsStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun regularAndDefaults (x1: kotlin.String, x2: kotlin.String): kotlin.Int declared in ' type=kotlin.reflect.KFunction2 origin=null reflectionTarget= + FUN name:testVarargsStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public final fun varargs (vararg xs: kotlin.String): kotlin.Int declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testCtorStar visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + fn: FUNCTION_REFERENCE 'public constructor (x: kotlin.String) [primary] declared in .C' type=kotlin.reflect.KFunction0<.C> origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt37131.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.fir.txt new file mode 100644 index 00000000000..df9e8d2d3e2 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.fir.txt @@ -0,0 +1,57 @@ +FILE fqName: fileName:/kt37131.kt + FUN name:foo visibility:public modality:FINAL <> (x:kotlin.String) returnType:kotlin.String + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (x: kotlin.String): kotlin.String declared in ' + GET_VAR 'x: kotlin.String declared in .foo' type=kotlin.String origin=null + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> (x:kotlin.String) returnType:.C [primary] + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:x visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'x: kotlin.String declared in .C.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.String + correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .C' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .C declared in .C.' type=.C origin=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 + FUN name:use visibility:public modality:FINAL <> (fn:kotlin.Function0) returnType:kotlin.Any + VALUE_PARAMETER name:fn index:0 type:kotlin.Function0 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Any origin=INVOKE + $this: GET_VAR 'fn: kotlin.Function0 declared in .use' type=kotlin.Function0 origin=null + FUN name:testFn visibility:public modality:FINAL <> () returnType:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testFn (): kotlin.Any declared in ' + CALL 'public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' type=kotlin.Any origin=null + fn: FUNCTION_REFERENCE 'public final fun foo (x: kotlin.String): kotlin.String declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= + FUN name:testCtor visibility:public modality:FINAL <> () returnType:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testCtor (): kotlin.Any declared in ' + CALL 'public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' type=kotlin.Any origin=null + fn: FUNCTION_REFERENCE 'public constructor (x: kotlin.String) [primary] declared in .C' type=kotlin.reflect.KFunction0<.C> origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt new file mode 100644 index 00000000000..0c05b1e7fa5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt @@ -0,0 +1,9 @@ +fun foo(x: String = ""): String = x + +class C(val x: String = "") + +fun use(fn: () -> Any) = fn() + +fun testFn() = use(::foo) + +fun testCtor() = use(::C) \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt new file mode 100644 index 00000000000..29968c8c89d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/kt37131.txt @@ -0,0 +1,67 @@ +FILE fqName: fileName:/kt37131.kt + FUN name:foo visibility:public modality:FINAL <> (x:kotlin.String) returnType:kotlin.String + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (x: kotlin.String): kotlin.String declared in ' + GET_VAR 'x: kotlin.String declared in .foo' type=kotlin.String origin=null + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> (x:kotlin.String) returnType:.C [primary] + VALUE_PARAMETER name:x index:0 type:kotlin.String + EXPRESSION_BODY + CONST String type=kotlin.String value="" + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:x visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final] + EXPRESSION_BODY + GET_VAR 'x: kotlin.String declared in .C.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.String + correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .C' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.String visibility:private [final]' type=kotlin.String origin=null + receiver: GET_VAR ': .C declared in .C.' type=.C origin=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 + FUN name:use visibility:public modality:FINAL <> (fn:kotlin.Function0) returnType:kotlin.Any + VALUE_PARAMETER name:fn index:0 type:kotlin.Function0 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Any origin=INVOKE + $this: GET_VAR 'fn: kotlin.Function0 declared in .use' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + FUN name:testFn visibility:public modality:FINAL <> () returnType:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testFn (): kotlin.Any declared in ' + CALL 'public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' type=kotlin.Any origin=null + fn: BLOCK type=kotlin.reflect.KFunction0 origin=null + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun foo (): kotlin.String declared in .testFn' + CALL 'public final fun foo (x: kotlin.String): kotlin.String declared in ' type=kotlin.String origin=null + FUNCTION_REFERENCE 'local final fun foo (): kotlin.String declared in .testFn' type=kotlin.reflect.KFunction0 origin=null reflectionTarget=null + FUN name:testCtor visibility:public modality:FINAL <> () returnType:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testCtor (): kotlin.Any declared in ' + CALL 'public final fun use (fn: kotlin.Function0): kotlin.Any declared in ' type=kotlin.Any origin=null + fn: BLOCK type=kotlin.reflect.KFunction0<.C> origin=null + FUN ADAPTER_FOR_CALLABLE_REFERENCE name: visibility:local modality:FINAL <> () returnType:.C + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): .C declared in .testCtor' + CONSTRUCTOR_CALL 'public constructor (x: kotlin.String) [primary] declared in .C' type=.C origin=null + FUNCTION_REFERENCE 'local final fun (): .C declared in .testCtor' type=kotlin.reflect.KFunction0<.C> origin=null reflectionTarget=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 706f43e48d0..0f27b71efcd 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1378,6 +1378,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.kt"); } + @TestMetadata("funWithDefaultParametersAsKCallableStar.kt") + public void testFunWithDefaultParametersAsKCallableStar() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/funWithDefaultParametersAsKCallableStar.kt"); + } + @TestMetadata("genericMember.kt") public void testGenericMember() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/genericMember.kt"); @@ -1388,6 +1393,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferences/importedFromObject.kt"); } + @TestMetadata("kt37131.kt") + public void testKt37131() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/kt37131.kt"); + } + @TestMetadata("typeArguments.kt") public void testTypeArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/typeArguments.kt");