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 0f2fd3f62d2..d0882dee226 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1354,6 +1354,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/boundInnerGenericConstructor.kt"); } + @TestMetadata("caoWithAdaptationForSam.kt") + public void testCaoWithAdaptationForSam() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.kt"); + } + @TestMetadata("constructorWithAdaptedArguments.kt") public void testConstructorWithAdaptedArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.kt"); @@ -1369,11 +1374,6 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/importedFromObject.kt"); } - @TestMetadata("letArrayOf.kt") - public void testLetArrayOf() throws Exception { - runTest("compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.kt"); - } - @TestMetadata("typeArguments.kt") public void testTypeArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/typeArguments.kt"); @@ -1384,6 +1384,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.kt"); } + @TestMetadata("withAdaptationForSam.kt") + public void testWithAdaptationForSam() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.kt"); + } + @TestMetadata("withAdaptedArguments.kt") public void testWithAdaptedArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt"); diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/ArrayAccessAssignmentReceiver.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/ArrayAccessAssignmentReceiver.kt index 527b317a6f5..2ab2fa3c3de 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/ArrayAccessAssignmentReceiver.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/ArrayAccessAssignmentReceiver.kt @@ -17,11 +17,18 @@ package org.jetbrains.kotlin.psi2ir.intermediate import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.declarations.IrVariable +import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl import org.jetbrains.kotlin.ir.expressions.impl.inlineStatement -import org.jetbrains.kotlin.ir.expressions.isAssignmentOperatorWithResult +import org.jetbrains.kotlin.ir.types.impl.originalKotlinType +import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid +import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid +import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid +import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi2ir.generators.CallGenerator import org.jetbrains.kotlin.psi2ir.generators.generateSamConversionForValueArgumentsIfRequired @@ -29,6 +36,7 @@ import org.jetbrains.kotlin.psi2ir.generators.pregenerateValueArgumentsUsing import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.checker.KotlinTypeChecker class ArrayAccessAssignmentReceiver( private val irArray: IrExpression, @@ -47,6 +55,10 @@ class ArrayAccessAssignmentReceiver( private val indexedGetDescriptor = indexedGetResolvedCall?.resultingDescriptor private val indexedSetDescriptor = indexedSetResolvedCall?.resultingDescriptor + private class CompoundAssignmentInfo { + val indexVariables = LinkedHashSet() + } + private val descriptor = indexedGetDescriptor ?: indexedSetDescriptor @@ -74,17 +86,132 @@ class ArrayAccessAssignmentReceiver( val irArrayValue = callGenerator.scope.createTemporaryVariableInBlock(callGenerator.context, irArray, irBlock, "array") + val compoundAssignmentInfo = CompoundAssignmentInfo() + irBlock.inlineStatement( withLValue( createLValue(kotlinType, irArrayValue) { i, irIndex -> - callGenerator.scope.createTemporaryVariableInBlock(callGenerator.context, irIndex, irBlock, "index$i") + val irIndexVar = callGenerator.scope.createTemporaryVariable(irIndex, "index$i") + compoundAssignmentInfo.indexVariables.add(irIndexVar) + irBlock.statements.add(irIndexVar) + VariableLValue(callGenerator.context, irIndexVar) } ) ) + postprocessSamConversionsInCompoundAssignment(irBlock, compoundAssignmentInfo) return irBlock } + private fun postprocessSamConversionsInCompoundAssignment( + irBlock: IrBlock, + compoundAssignmentInfo: CompoundAssignmentInfo + ) { + val samConversionsCollector = SamConversionsCollector(compoundAssignmentInfo) + irBlock.acceptChildrenVoid(samConversionsCollector) + + if (samConversionsCollector.samConversionsPerVariable.isEmpty()) return + + val samConvertedVars = hashMapOf() + for ((irIndexVar, samConversions) in samConversionsCollector.samConversionsPerVariable) { + var mostSpecificSamConversion: IrTypeOperatorCall = samConversions.first() + for (samConversion in samConversions) { + if (samConversion === mostSpecificSamConversion) continue + val lastType = mostSpecificSamConversion.operandKotlinType + val nextType = samConversion.operandKotlinType + if (KotlinTypeChecker.DEFAULT.isSubtypeOf(nextType, lastType)) { + mostSpecificSamConversion = samConversion + } else if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(lastType, nextType)) { + throw AssertionError("Unrelated types in SAM conversion for index variable: $lastType, $nextType") + } + } + val irSamConvertedVarInitializer = createSamConvertedVarInitializer(irIndexVar, mostSpecificSamConversion) + val irSamConvertedVar = callGenerator.scope.createTemporaryVariable(irSamConvertedVarInitializer, "sam") + val index = irBlock.statements.indexOf(irIndexVar) + irBlock.statements[index] = irSamConvertedVar + samConvertedVars[irIndexVar] = irSamConvertedVar + } + + irBlock.transformChildrenVoid(SamConversionsRewriter(samConvertedVars)) + } + + private fun createSamConvertedVarInitializer(irIndexVar: IrVariable, mostSpecificSamConversion: IrTypeOperatorCall): IrExpression { + val irIndexVarInitializer = irIndexVar.initializer!! + val startOffset = irIndexVarInitializer.startOffset + val endOffset = irIndexVarInitializer.endOffset + + val implicitCast = mostSpecificSamConversion.argument as IrTypeOperatorCall + + return IrTypeOperatorCallImpl( + startOffset, endOffset, + mostSpecificSamConversion.type, + IrTypeOperator.SAM_CONVERSION, + mostSpecificSamConversion.typeOperand, + IrTypeOperatorCallImpl( + startOffset, endOffset, + implicitCast.type, + IrTypeOperator.IMPLICIT_CAST, + implicitCast.typeOperand, + irIndexVarInitializer + ) + ) + } + + private val IrTypeOperatorCall.operandKotlinType + get() = typeOperand.originalKotlinType!! + + private class SamConversionsCollector( + private val compoundAssignmentInfo: CompoundAssignmentInfo + ) : IrElementVisitorVoid { + val samConversionsPerVariable = HashMap>() + + override fun visitElement(element: IrElement) { + element.acceptChildrenVoid(this) + } + + override fun visitTypeOperator(expression: IrTypeOperatorCall) { + expression.acceptChildrenVoid(this) + val irGetVar = expression.getSamConvertedGetValue() + if (irGetVar != null) { + val valueDeclaration = irGetVar.symbol.owner + if (valueDeclaration is IrVariable && valueDeclaration in compoundAssignmentInfo.indexVariables) { + samConversionsPerVariable.getOrPut(valueDeclaration) { ArrayList() }.add(expression) + } + } + } + } + + private class SamConversionsRewriter( + private val replacementVars: Map + ) : IrElementTransformerVoid() { + override fun visitElement(element: IrElement): IrElement { + return element.apply { transformChildrenVoid() } + } + + override fun visitTypeOperator(expression: IrTypeOperatorCall): IrExpression { + val irGetVar = expression.getSamConvertedGetValue() + if (irGetVar != null) { + val valueDeclaration = irGetVar.symbol.owner + val replacementVar = replacementVars[valueDeclaration] + if (replacementVar != null) { + return IrGetValueImpl(expression.startOffset, expression.endOffset, replacementVar.symbol, null) + } + } + + return expression.apply { transformChildrenVoid() } + } + + override fun visitGetValue(expression: IrGetValue): IrExpression { + val symbol = expression.symbol + if (symbol.owner in replacementVars) { + throw AssertionError( + "SAM-converted index variable ${symbol.descriptor} is present in get/set calls in non-converted" + ) + } + return expression + } + } + private fun createLValue( kotlinType: KotlinType, irArrayValue: IntermediateValue, @@ -126,4 +253,17 @@ class ArrayAccessAssignmentReceiver( value?.let { lastArgument = it } callGenerator.statementGenerator.generateSamConversionForValueArgumentsIfRequired(this, resolvedCall) } + + companion object { + internal fun IrTypeOperatorCall.getSamConvertedGetValue(): IrGetValue? { + if (operator != IrTypeOperator.SAM_CONVERSION) return null + val arg0 = argument + if (arg0 !is IrTypeOperatorCall) return null + if (arg0.operator != IrTypeOperator.IMPLICIT_CAST) return null + val arg1 = arg0.argument + if (arg1 !is IrGetValue) return null + if (arg1.symbol.owner !is IrVariable) return null + return arg1 + } + } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt index a289eb757ba..de94df35b28 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt @@ -23,14 +23,14 @@ import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.psi2ir.generators.CallGenerator class LValueWithGetterAndSetterCalls( - val callGenerator: CallGenerator, - val descriptor: CallableDescriptor, - val getterCall: () -> CallBuilder?, - val setterCall: (IrExpression) -> CallBuilder?, + private val callGenerator: CallGenerator, + private val descriptor: CallableDescriptor, + private val getterCall: () -> CallBuilder?, + private val setterCall: (IrExpression) -> CallBuilder?, override val type: IrType, - val startOffset: Int, - val endOffset: Int, - val origin: IrStatementOrigin? = null + private val startOffset: Int, + private val endOffset: Int, + private val origin: IrStatementOrigin? = null ) : LValue { override fun load(): IrExpression { diff --git a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.txt new file mode 100644 index 00000000000..2c806c27c61 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.fir.txt @@ -0,0 +1,137 @@ +FILE fqName: fileName:/caoWithAdaptationForSam.kt + CLASS INTERFACE name:IFoo modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo, i:kotlin.Int) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IFoo + VALUE_PARAMETER name:i index:0 type:kotlin.Int + 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 INTERFACE name:IFoo2 modality:ABSTRACT visibility:public superTypes:[.IFoo] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo2 + FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo, i:kotlin.Int) returnType:kotlin.Unit [fake_override] + overridden: + public abstract fun foo (i: kotlin.Int): kotlin.Unit declared in .IFoo + $this: VALUE_PARAMETER name: type:.IFoo + VALUE_PARAMETER name:i index:0 type:kotlin.Int + 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:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:private <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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:B modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B + CONSTRUCTOR visibility:private <> () returnType:.B [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:B modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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:get visibility:public modality:FINAL <> ($receiver:.A, i:.IFoo) returnType:kotlin.Int [operator] + $receiver: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:i index:0 type:.IFoo + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:set visibility:public modality:FINAL <> ($receiver:.A, i:.IFoo, newValue:kotlin.Int) returnType:kotlin.Unit [operator] + $receiver: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:i index:0 type:.IFoo + VALUE_PARAMETER name:newValue index:1 type:kotlin.Int + BLOCK_BODY + FUN name:get visibility:public modality:FINAL <> ($receiver:.B, i:.IFoo) returnType:kotlin.Int [operator] + $receiver: VALUE_PARAMETER name: type:.B + VALUE_PARAMETER name:i index:0 type:.IFoo + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:set visibility:public modality:FINAL <> ($receiver:.B, i:.IFoo2, newValue:kotlin.Int) returnType:kotlin.Unit [operator] + $receiver: VALUE_PARAMETER name: type:.B + VALUE_PARAMETER name:i index:0 type:.IFoo2 + VALUE_PARAMETER name:newValue index:1 type:kotlin.Int + BLOCK_BODY + FUN name:withVararg visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun withVararg (xs: kotlin.IntArray): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=42 + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'FirArraySetCall (resolve isn't supported yet)' type=kotlin.Unit + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'FirArraySetCall (resolve isn't supported yet)' type=kotlin.Unit + FUN name:test3 visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + ERROR_CALL 'FirArraySetCall (resolve isn't supported yet)' type=kotlin.Unit + FUN name:test4 visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + WHEN type=kotlin.Unit origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.IFoo + GET_VAR 'fn: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null + then: BLOCK type=kotlin.Unit origin=null + ERROR_CALL 'FirArraySetCall (resolve isn't supported yet)' type=kotlin.Unit + FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:a index:0 type:kotlin.Any + BLOCK_BODY + TYPE_OP type=kotlin.Function1 origin=CAST typeOperand=kotlin.Function1 + GET_VAR 'a: kotlin.Any declared in .test5' type=kotlin.Any origin=null + ERROR_CALL 'FirArraySetCall (resolve isn't supported yet)' type=kotlin.Unit + FUN name:test6 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:a index:0 type:kotlin.Any + BLOCK_BODY + TYPE_OP type=kotlin.Function1 origin=CAST typeOperand=kotlin.Function1 + GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null + TYPE_OP type=.IFoo origin=CAST typeOperand=.IFoo + GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Function1 origin=null + ERROR_CALL 'FirArraySetCall (resolve isn't supported yet)' type=kotlin.Unit diff --git a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.kt b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.kt new file mode 100644 index 00000000000..f1e5877234e --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.kt @@ -0,0 +1,47 @@ +// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions + +fun interface IFoo { + fun foo(i: Int) +} + +fun interface IFoo2 : IFoo + +object A +object B + +operator fun A.get(i: IFoo) = 1 +operator fun A.set(i: IFoo, newValue: Int) {} + +operator fun B.get(i: IFoo) = 1 +operator fun B.set(i: IFoo2, newValue: Int) {} + +fun withVararg(vararg xs: Int) = 42 + +fun test1() { + A[::withVararg] += 1 +} + +fun test2() { + B[::withVararg] += 1 +} + +fun test3(fn: (Int) -> Unit) { + A[fn] += 1 +} + +fun test4(fn: (Int) -> Unit) { + if (fn is IFoo) { + A[fn] += 1 + } +} + +fun test5(a: Any) { + a as (Int) -> Unit + A[a] += 1 +} + +fun test6(a: Any) { + a as (Int) -> Unit + a as IFoo + A[a] += 1 +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.txt b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.txt new file mode 100644 index 00000000000..d0a2f19daa2 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.txt @@ -0,0 +1,237 @@ +FILE fqName: fileName:/caoWithAdaptationForSam.kt + CLASS INTERFACE name:IFoo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo, i:kotlin.Int) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IFoo + VALUE_PARAMETER name:i index:0 type:kotlin.Int + 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 INTERFACE name:IFoo2 modality:ABSTRACT visibility:public [fun] superTypes:[.IFoo] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo2 + FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo, i:kotlin.Int) returnType:kotlin.Unit [fake_override] + overridden: + public abstract fun foo (i: kotlin.Int): kotlin.Unit declared in .IFoo + $this: VALUE_PARAMETER name: type:.IFoo + VALUE_PARAMETER name:i index:0 type:kotlin.Int + 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 [fake_override,operator] declared in .IFoo + $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 [fake_override] declared in .IFoo + $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 [fake_override] declared in .IFoo + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:private <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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:B modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B + CONSTRUCTOR visibility:private <> () returnType:.B [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:B modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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:get visibility:public modality:FINAL <> ($receiver:.A, i:.IFoo) returnType:kotlin.Int [operator] + $receiver: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:i index:0 type:.IFoo + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:set visibility:public modality:FINAL <> ($receiver:.A, i:.IFoo, newValue:kotlin.Int) returnType:kotlin.Unit [operator] + $receiver: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:i index:0 type:.IFoo + VALUE_PARAMETER name:newValue index:1 type:kotlin.Int + BLOCK_BODY + FUN name:get visibility:public modality:FINAL <> ($receiver:.B, i:.IFoo) returnType:kotlin.Int [operator] + $receiver: VALUE_PARAMETER name: type:.B + VALUE_PARAMETER name:i index:0 type:.IFoo + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' + CONST Int type=kotlin.Int value=1 + FUN name:set visibility:public modality:FINAL <> ($receiver:.B, i:.IFoo2, newValue:kotlin.Int) returnType:kotlin.Unit [operator] + $receiver: VALUE_PARAMETER name: type:.B + VALUE_PARAMETER name:i index:0 type:.IFoo2 + VALUE_PARAMETER name:newValue index:1 type:kotlin.Int + BLOCK_BODY + FUN name:withVararg visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=42 + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BLOCK type=kotlin.Unit origin=PLUSEQ + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.A [val] + GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A + VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:.IFoo [val] + TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo + BLOCK type=kotlin.reflect.KFunction1 origin=null + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .test1.withVararg' type=kotlin.Int origin=null + FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .test1' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null + CALL 'public final fun set (i: .IFoo, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ + $receiver: GET_VAR 'val tmp_0: .A [val] declared in .test1' type=.A origin=null + i: GET_VAR 'val tmp_1: .IFoo [val] declared in .test1' type=.IFoo origin=null + newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ + $this: CALL 'public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' type=kotlin.Int origin=PLUSEQ + $receiver: GET_VAR 'val tmp_0: .A [val] declared in .test1' type=.A origin=null + i: GET_VAR 'val tmp_1: .IFoo [val] declared in .test1' type=.IFoo origin=null + other: CONST Int type=kotlin.Int value=1 + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BLOCK type=kotlin.Unit origin=PLUSEQ + VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:.B [val] + GET_OBJECT 'CLASS OBJECT name:B modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.B + VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:.IFoo2 [val] + TYPE_OP type=.IFoo2 origin=SAM_CONVERSION typeOperand=.IFoo2 + BLOCK type=kotlin.reflect.KFunction1 origin=null + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .test2.withVararg' type=kotlin.Int origin=null + FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .test2' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null + CALL 'public final fun set (i: .IFoo2, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ + $receiver: GET_VAR 'val tmp_2: .B [val] declared in .test2' type=.B origin=null + i: GET_VAR 'val tmp_3: .IFoo2 [val] declared in .test2' type=.IFoo2 origin=null + newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ + $this: CALL 'public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' type=kotlin.Int origin=PLUSEQ + $receiver: GET_VAR 'val tmp_2: .B [val] declared in .test2' type=.B origin=null + i: GET_VAR 'val tmp_3: .IFoo2 [val] declared in .test2' type=.IFoo2 origin=null + other: CONST Int type=kotlin.Int value=1 + FUN name:test3 visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + BLOCK type=kotlin.Unit origin=PLUSEQ + VAR IR_TEMPORARY_VARIABLE name:tmp_4 type:.A [val] + GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A + VAR IR_TEMPORARY_VARIABLE name:tmp_5 type:.IFoo [val] + TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo + GET_VAR 'fn: kotlin.Function1 declared in .test3' type=kotlin.Function1 origin=null + CALL 'public final fun set (i: .IFoo, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ + $receiver: GET_VAR 'val tmp_4: .A [val] declared in .test3' type=.A origin=null + i: GET_VAR 'val tmp_5: .IFoo [val] declared in .test3' type=.IFoo origin=null + newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ + $this: CALL 'public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' type=kotlin.Int origin=PLUSEQ + $receiver: GET_VAR 'val tmp_4: .A [val] declared in .test3' type=.A origin=null + i: GET_VAR 'val tmp_5: .IFoo [val] declared in .test3' type=.IFoo origin=null + other: CONST Int type=kotlin.Int value=1 + FUN name:test4 visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 + BLOCK_BODY + WHEN type=kotlin.Unit origin=IF + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.IFoo + GET_VAR 'fn: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null + then: BLOCK type=kotlin.Unit origin=null + BLOCK type=kotlin.Unit origin=PLUSEQ + VAR IR_TEMPORARY_VARIABLE name:tmp_6 type:.A [val] + GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A + VAR IR_TEMPORARY_VARIABLE name:tmp_7 type:kotlin.Function1 [val] + GET_VAR 'fn: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null + CALL 'public final fun set (i: .IFoo, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ + $receiver: GET_VAR 'val tmp_6: .A [val] declared in .test4' type=.A origin=null + i: TYPE_OP type=.IFoo origin=IMPLICIT_CAST typeOperand=.IFoo + GET_VAR 'val tmp_7: kotlin.Function1 [val] declared in .test4' type=kotlin.Function1 origin=null + newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ + $this: CALL 'public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' type=kotlin.Int origin=PLUSEQ + $receiver: GET_VAR 'val tmp_6: .A [val] declared in .test4' type=.A origin=null + i: TYPE_OP type=.IFoo origin=IMPLICIT_CAST typeOperand=.IFoo + GET_VAR 'val tmp_7: kotlin.Function1 [val] declared in .test4' type=kotlin.Function1 origin=null + other: CONST Int type=kotlin.Int value=1 + FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:a index:0 type:kotlin.Any + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + TYPE_OP type=kotlin.Function1 origin=CAST typeOperand=kotlin.Function1 + GET_VAR 'a: kotlin.Any declared in .test5' type=kotlin.Any origin=null + BLOCK type=kotlin.Unit origin=PLUSEQ + VAR IR_TEMPORARY_VARIABLE name:tmp_8 type:.A [val] + GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A + VAR IR_TEMPORARY_VARIABLE name:tmp_9 type:.IFoo [val] + TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo + TYPE_OP type=kotlin.Function1<@[ParameterName(name = 'i')] kotlin.Int, kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[ParameterName(name = 'i')] kotlin.Int, kotlin.Unit> + GET_VAR 'a: kotlin.Any declared in .test5' type=kotlin.Any origin=null + CALL 'public final fun set (i: .IFoo, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ + $receiver: GET_VAR 'val tmp_8: .A [val] declared in .test5' type=.A origin=null + i: GET_VAR 'val tmp_9: .IFoo [val] declared in .test5' type=.IFoo origin=null + newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ + $this: CALL 'public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' type=kotlin.Int origin=PLUSEQ + $receiver: GET_VAR 'val tmp_8: .A [val] declared in .test5' type=.A origin=null + i: GET_VAR 'val tmp_9: .IFoo [val] declared in .test5' type=.IFoo origin=null + other: CONST Int type=kotlin.Int value=1 + FUN name:test6 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit + VALUE_PARAMETER name:a index:0 type:kotlin.Any + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + TYPE_OP type=kotlin.Function1 origin=CAST typeOperand=kotlin.Function1 + GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + TYPE_OP type=.IFoo origin=CAST typeOperand=.IFoo + GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null + BLOCK type=kotlin.Unit origin=PLUSEQ + VAR IR_TEMPORARY_VARIABLE name:tmp_10 type:.A [val] + GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A + VAR IR_TEMPORARY_VARIABLE name:tmp_11 type:kotlin.Any [val] + GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null + CALL 'public final fun set (i: .IFoo, newValue: kotlin.Int): kotlin.Unit [operator] declared in ' type=kotlin.Unit origin=PLUSEQ + $receiver: GET_VAR 'val tmp_10: .A [val] declared in .test6' type=.A origin=null + i: TYPE_OP type=.IFoo origin=IMPLICIT_CAST typeOperand=.IFoo + GET_VAR 'val tmp_11: kotlin.Any [val] declared in .test6' type=kotlin.Any origin=null + newValue: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ + $this: CALL 'public final fun get (i: .IFoo): kotlin.Int [operator] declared in ' type=kotlin.Int origin=PLUSEQ + $receiver: GET_VAR 'val tmp_10: .A [val] declared in .test6' type=.A origin=null + i: TYPE_OP type=.IFoo origin=IMPLICIT_CAST typeOperand=.IFoo + GET_VAR 'val tmp_11: kotlin.Any [val] declared in .test6' type=kotlin.Any origin=null + other: CONST Int type=kotlin.Int value=1 diff --git a/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.fir.txt deleted file mode 100644 index f8195b98522..00000000000 --- a/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.fir.txt +++ /dev/null @@ -1,6 +0,0 @@ -FILE fqName: fileName:/letArrayOf.kt - FUN name:test visibility:public modality:FINAL <> () returnType:IrErrorType - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test (): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - FUNCTION_REFERENCE 'public final fun arrayOf (elements: kotlin.Array): kotlin.Array [inline] declared in kotlin' type=kotlin.reflect.KFunction1, kotlin.Array> origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.kt b/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.kt deleted file mode 100644 index 490b3fe7161..00000000000 --- a/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.kt +++ /dev/null @@ -1,3 +0,0 @@ -// !LANGUAGE: +NewInference - -fun test() = "OK".let(::arrayOf) \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.txt b/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.txt deleted file mode 100644 index 75b55fa82b7..00000000000 --- a/compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.txt +++ /dev/null @@ -1,18 +0,0 @@ -FILE fqName: fileName:/letArrayOf.kt - FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Array - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Array declared in ' - CALL 'public final fun let (block: kotlin.Function1): R of kotlin.let [inline] declared in kotlin' type=kotlin.Array origin=null - : kotlin.String - : kotlin.Array - $receiver: CONST String type=kotlin.String value="OK" - block: BLOCK type=kotlin.reflect.KFunction1> origin=null - FUN ADAPTER_FOR_CALLABLE_REFERENCE name:arrayOf visibility:local modality:FINAL <> (p0:kotlin.String) returnType:kotlin.Array [inline] - VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun arrayOf (p0: kotlin.String): kotlin.Array [inline] declared in .test' - CALL 'public final fun arrayOf (vararg elements: T of kotlin.arrayOf): kotlin.Array [inline] declared in kotlin' type=kotlin.Array origin=null - : kotlin.String - elements: VARARG type=kotlin.Array varargElementType=kotlin.String - GET_VAR 'p0: kotlin.String declared in .test.arrayOf' type=kotlin.String origin=null - FUNCTION_REFERENCE 'local final fun arrayOf (p0: kotlin.String): kotlin.Array [inline] declared in .test' type=kotlin.reflect.KFunction1> origin=null reflectionTarget=null diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.txt new file mode 100644 index 00000000000..3a2dfe27015 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.fir.txt @@ -0,0 +1,34 @@ +FILE fqName: fileName:/withAdaptationForSam.kt + CLASS INTERFACE name:IFoo modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo, i:kotlin.Int) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IFoo + VALUE_PARAMETER name:i index:0 type:kotlin.Int + 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:useFoo visibility:public modality:FINAL <> (foo:.IFoo) returnType:kotlin.Unit + VALUE_PARAMETER name:foo index:0 type:.IFoo + BLOCK_BODY + FUN name:useVarargFoo visibility:public modality:FINAL <> (foos:kotlin.Array<.IFoo>) returnType:kotlin.Unit + VALUE_PARAMETER name:foos index:0 type:kotlin.Array<.IFoo> + BLOCK_BODY + FUN name:withVararg visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun withVararg (xs: kotlin.IntArray): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=42 + FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'public final fun withVararg (xs: kotlin.IntArray): kotlin.Int declared in ' type=kotlin.reflect.KFunction1 origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.kt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.kt new file mode 100644 index 00000000000..fccbeec46a7 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions + +fun interface IFoo { + fun foo(i: Int) +} + +fun useFoo(foo: IFoo) {} + +fun useVarargFoo(vararg foos: IFoo) {} + +fun withVararg(vararg xs: Int) = 42 + +fun test() { + useFoo(::withVararg) +} + +// TODO +//fun testVarargOfSams() { +// useVarargFoo(::withVararg) +//} \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.txt b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.txt new file mode 100644 index 00000000000..acd0b3c89fa --- /dev/null +++ b/compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.txt @@ -0,0 +1,43 @@ +FILE fqName: fileName:/withAdaptationForSam.kt + CLASS INTERFACE name:IFoo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.IFoo + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.IFoo, i:kotlin.Int) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.IFoo + VALUE_PARAMETER name:i index:0 type:kotlin.Int + 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:useFoo visibility:public modality:FINAL <> (foo:.IFoo) returnType:kotlin.Unit + VALUE_PARAMETER name:foo index:0 type:.IFoo + BLOCK_BODY + FUN name:useVarargFoo visibility:public modality:FINAL <> (foos:kotlin.Array.IFoo>) returnType:kotlin.Unit + VALUE_PARAMETER name:foos index:0 type:kotlin.Array.IFoo> varargElementType:.IFoo [vararg] + BLOCK_BODY + FUN name:withVararg visibility:public modality:FINAL <> (xs:kotlin.IntArray) returnType:kotlin.Int + VALUE_PARAMETER name:xs index:0 type:kotlin.IntArray varargElementType:kotlin.Int [vararg] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' + CONST Int type=kotlin.Int value=42 + FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun useFoo (foo: .IFoo): kotlin.Unit declared in ' type=kotlin.Unit origin=null + foo: TYPE_OP type=.IFoo origin=SAM_CONVERSION typeOperand=.IFoo + BLOCK type=kotlin.reflect.KFunction1 origin=null + FUN ADAPTER_FOR_CALLABLE_REFERENCE name:withVararg visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun withVararg (vararg xs: kotlin.Int): kotlin.Int declared in ' type=kotlin.Int origin=null + xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int + GET_VAR 'p0: kotlin.Int declared in .test.withVararg' type=kotlin.Int origin=null + FUNCTION_REFERENCE 'local final fun withVararg (p0: kotlin.Int): kotlin.Unit declared in .test' type=kotlin.reflect.KFunction1 origin=null reflectionTarget=null diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 3cc6edc1c56..6fa72386220 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -8118,83 +8118,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } - @TestMetadata("compiler/testData/codegen/box/coroutines/noStdLib") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class NoStdLib extends AbstractLightAnalysisModeTest { - @TestMetadata("breakFinally.kt") - public void ignoreBreakFinally_1_2() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/breakFinally.kt", "kotlin.coroutines.experimental"); - } - - @TestMetadata("breakFinally.kt") - public void ignoreBreakFinally_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/breakFinally.kt", "kotlin.coroutines"); - } - - @TestMetadata("breakStatement.kt") - public void ignoreBreakStatement_1_2() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/breakStatement.kt", "kotlin.coroutines.experimental"); - } - - @TestMetadata("breakStatement.kt") - public void ignoreBreakStatement_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/breakStatement.kt", "kotlin.coroutines"); - } - - @TestMetadata("crossinline.kt") - public void ignoreCrossinline_1_2() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/crossinline.kt", "kotlin.coroutines.experimental"); - } - - @TestMetadata("crossinline.kt") - public void ignoreCrossinline_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/crossinline.kt", "kotlin.coroutines"); - } - - @TestMetadata("ifStatement.kt") - public void ignoreIfStatement_1_2() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/ifStatement.kt", "kotlin.coroutines.experimental"); - } - - @TestMetadata("ifStatement.kt") - public void ignoreIfStatement_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/ifStatement.kt", "kotlin.coroutines"); - } - - @TestMetadata("stateMachine.kt") - public void ignoreStateMachine_1_2() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/stateMachine.kt", "kotlin.coroutines.experimental"); - } - - @TestMetadata("stateMachine.kt") - public void ignoreStateMachine_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/stateMachine.kt", "kotlin.coroutines"); - } - - @TestMetadata("switchLikeWhen.kt") - public void ignoreSwitchLikeWhen_1_2() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/switchLikeWhen.kt", "kotlin.coroutines.experimental"); - } - - @TestMetadata("switchLikeWhen.kt") - public void ignoreSwitchLikeWhen_1_3() throws Exception { - runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/noStdLib/switchLikeWhen.kt", "kotlin.coroutines"); - } - - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); - } - - private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { - KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.JVM, testDataFilePath); - } - - public void testAllFilesPresentInNoStdLib() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/noStdLib"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); - } - } - @TestMetadata("compiler/testData/codegen/box/coroutines/redundantLocalsElimination") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 3780d2eab38..8630feb05d0 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1353,6 +1353,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferences/boundInnerGenericConstructor.kt"); } + @TestMetadata("caoWithAdaptationForSam.kt") + public void testCaoWithAdaptationForSam() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.kt"); + } + @TestMetadata("constructorWithAdaptedArguments.kt") public void testConstructorWithAdaptedArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/constructorWithAdaptedArguments.kt"); @@ -1368,11 +1373,6 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferences/importedFromObject.kt"); } - @TestMetadata("letArrayOf.kt") - public void testLetArrayOf() throws Exception { - runTest("compiler/testData/ir/irText/expressions/callableReferences/letArrayOf.kt"); - } - @TestMetadata("typeArguments.kt") public void testTypeArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/typeArguments.kt"); @@ -1383,6 +1383,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/callableReferences/unboundMemberReferenceWithAdaptedArguments.kt"); } + @TestMetadata("withAdaptationForSam.kt") + public void testWithAdaptationForSam() throws Exception { + runTest("compiler/testData/ir/irText/expressions/callableReferences/withAdaptationForSam.kt"); + } + @TestMetadata("withAdaptedArguments.kt") public void testWithAdaptedArguments() throws Exception { runTest("compiler/testData/ir/irText/expressions/callableReferences/withAdaptedArguments.kt");