diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index c75df2a8046..ddfc49782f8 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -2494,6 +2494,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/firProblems/FlushFromAnonymous.kt"); } + @Test + @TestMetadata("functionLiteralGenericSignature.kt") + public void testFunctionLiteralGenericSignature() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt"); + } + @Test @TestMetadata("ImplicitReceiverStack.kt") public void testImplicitReceiverStack() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index cd550a7ffda..6ba45eabd0f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -747,6 +747,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor ) } var lambda = anonymousFunction + val initialReturnTypeRef = lambda.returnTypeRef val valueParameters = when { resolvedLambdaAtom != null -> obtainValueParametersFromResolvedLambdaAtom(resolvedLambdaAtom, lambda) else -> lambda.valueParameters @@ -788,17 +789,22 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor (it as? FirExpression)?.typeRef is FirImplicitUnitTypeRef } - val returnType = - if (implicitReturns.isNotEmpty() || lambda.returnType?.isUnit == true) { + val returnType = when { + initialReturnTypeRef is FirResolvedTypeRef -> { + initialReturnTypeRef.coneType + } + implicitReturns.isNotEmpty() || lambda.returnType?.isUnit == true -> { // i.e., early return, e.g., l@{ ... return@l ... } // Note that the last statement will be coerced to Unit if needed. session.builtinTypes.unitType.type - } else { + } + else -> { // Otherwise, compute the common super type of all possible return expressions session.typeContext.commonSuperTypeOrNull( returnStatements.mapNotNull { (it as? FirExpression)?.resultType?.coneType } ) ?: session.builtinTypes.unitType.type } + } lambda.replaceReturnTypeRef( lambda.returnTypeRef.resolvedTypeFromPrototype(returnType).also { session.lookupTracker?.recordTypeResolveAsLookup(it, lambda.source, null) diff --git a/compiler/testData/codegen/box/reflection/genericSignature/functionLiteralGenericSignature.kt b/compiler/testData/codegen/box/reflection/genericSignature/functionLiteralGenericSignature.kt index 68755cc3d00..5f70c0e0333 100644 --- a/compiler/testData/codegen/box/reflection/genericSignature/functionLiteralGenericSignature.kt +++ b/compiler/testData/codegen/box/reflection/genericSignature/functionLiteralGenericSignature.kt @@ -1,6 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: Fail, expected: kotlin.jvm.functions.Function1, java.util.List>, -// actual: interface kotlin.jvm.functions.Function1 // TARGET_BACKEND: JVM import java.util.Date diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt index 14967f7b962..c631a18cff1 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt @@ -3,16 +3,16 @@ fun test1(): Int = { return 1 } fun test2(): Int = { 1 } -val test3: () -> Int = fun (): Int = { return 1 } -val test4: () -> Int = fun (): Int = { 1 } +val test3: () -> Int = fun (): Int = { return 1 } +val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 fun outer() { fun test1(): Int = { return 1 } fun test2(): Int = { 1 } - val test3: () -> Int = fun (): Int = { return 1 } - val test4: () -> Int = fun (): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 } @@ -20,16 +20,16 @@ fun outer() { class Outer { fun test1(): Int = { return 1 } fun test2(): Int = { 1 } - val test3: () -> Int = fun (): Int = { return 1 } - val test4: () -> Int = fun (): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 class Nested { fun test1(): Int = { return 1 } fun test2(): Int = { 1 } - val test3: () -> Int = fun (): Int = { return 1 } - val test4: () -> Int = fun (): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 } diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt index 931f8557a41..c7f841b7f2f 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.fir.kt @@ -3,10 +3,10 @@ interface A fun devNull(a: Any?){} -val generic_fun = fun(t: T): T = null!! -val extension_generic_fun = funT.(t: T): T = null!! +val generic_fun = fun(t: T): T = null!! +val extension_generic_fun = funT.(t: T): T = null!! -fun fun_with_where() = fun T.(t: T): T where T: A = null!! +fun fun_with_where() = fun T.(t: T): T where T: A = null!! fun outer() { diff --git a/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.fir.ir.txt b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.fir.ir.txt new file mode 100644 index 00000000000..ef23b4cf2d9 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.fir.ir.txt @@ -0,0 +1,110 @@ +FILE fqName: fileName:/functionLiteralGenericSignature.kt + PROPERTY name:unitFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:unitFun type:kotlin.Function0 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .unitFun' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function0 + correspondingProperty: PROPERTY name:unitFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function0 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:unitFun type:kotlin.Function0 visibility:private [final,static]' type=kotlin.Function0 origin=null + PROPERTY name:intFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:intFun type:kotlin.Function0 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .intFun' + CONST Int type=kotlin.Int value=42 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function0 + correspondingProperty: PROPERTY name:intFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function0 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:intFun type:kotlin.Function0 visibility:private [final,static]' type=kotlin.Function0 origin=null + PROPERTY name:stringParamFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:stringParamFun type:kotlin.Function1 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:kotlin.String) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (x: kotlin.String): kotlin.Unit declared in .stringParamFun' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1 + correspondingProperty: PROPERTY name:stringParamFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:stringParamFun type:kotlin.Function1 visibility:private [final,static]' type=kotlin.Function1 origin=null + PROPERTY name:listFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:listFun type:kotlin.Function1, kotlin.collections.List> visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1, kotlin.collections.List> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (l:kotlin.collections.List) returnType:kotlin.collections.List + VALUE_PARAMETER name:l index:0 type:kotlin.collections.List + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (l: kotlin.collections.List): kotlin.collections.List declared in .listFun' + GET_VAR 'l: kotlin.collections.List declared in .listFun.' type=kotlin.collections.List origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1, kotlin.collections.List> + correspondingProperty: PROPERTY name:listFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1, kotlin.collections.List> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:listFun type:kotlin.Function1, kotlin.collections.List> visibility:private [final,static]' type=kotlin.Function1, kotlin.collections.List> origin=null + PROPERTY name:mutableListFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:mutableListFun type:kotlin.Function1, kotlin.collections.MutableList> visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1, kotlin.collections.MutableList> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (l:kotlin.collections.MutableList) returnType:kotlin.collections.MutableList + VALUE_PARAMETER name:l index:0 type:kotlin.collections.MutableList + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (l: kotlin.collections.MutableList): kotlin.collections.MutableList declared in .mutableListFun' + CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.Nothing origin=EXCLEXCL + : kotlin.Nothing + arg0: CONST Null type=kotlin.Nothing? value=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1, kotlin.collections.MutableList> + correspondingProperty: PROPERTY name:mutableListFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1, kotlin.collections.MutableList> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:mutableListFun type:kotlin.Function1, kotlin.collections.MutableList> visibility:private [final,static]' type=kotlin.Function1, kotlin.collections.MutableList> origin=null + PROPERTY name:funWithIn visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:funWithIn type:kotlin.Function1, kotlin.Unit> visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:kotlin.Comparable) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.Comparable + BLOCK_BODY + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1, kotlin.Unit> + correspondingProperty: PROPERTY name:funWithIn visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1, kotlin.Unit> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:funWithIn type:kotlin.Function1, kotlin.Unit> visibility:private [final,static]' type=kotlin.Function1, kotlin.Unit> origin=null + PROPERTY name:extensionFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:extensionFun type:@[ExtensionFunctionType] kotlin.Function1 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Any) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:kotlin.Any + BLOCK_BODY + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:@[ExtensionFunctionType] kotlin.Function1 + correspondingProperty: PROPERTY name:extensionFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): @[ExtensionFunctionType] kotlin.Function1 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:extensionFun type:@[ExtensionFunctionType] kotlin.Function1 visibility:private [final,static]' type=@[ExtensionFunctionType] kotlin.Function1 origin=null + PROPERTY name:extensionWithArgFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:extensionWithArgFun type:@[ExtensionFunctionType] kotlin.Function2 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function2 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Long, x:kotlin.Any) returnType:java.util.Date + $receiver: VALUE_PARAMETER name: type:kotlin.Long + VALUE_PARAMETER name:x index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (x: kotlin.Any): java.util.Date declared in .extensionWithArgFun' + CONSTRUCTOR_CALL 'public constructor () declared in java.util.Date' type=java.util.Date origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:@[ExtensionFunctionType] kotlin.Function2 + correspondingProperty: PROPERTY name:extensionWithArgFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): @[ExtensionFunctionType] kotlin.Function2 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:extensionWithArgFun type:@[ExtensionFunctionType] kotlin.Function2 visibility:private [final,static]' type=@[ExtensionFunctionType] kotlin.Function2 origin=null diff --git a/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.fir.kt.txt b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.fir.kt.txt new file mode 100644 index 00000000000..aa648f6b93f --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.fir.kt.txt @@ -0,0 +1,53 @@ +val unitFun: Function0 + field = local fun () { + return Unit + } + + get + +val intFun: Function0 + field = local fun (): Int { + return 42 + } + + get + +val stringParamFun: Function1 + field = local fun (x: String) { + return Unit + } + + get + +val listFun: Function1, List> + field = local fun (l: List): List { + return l + } + + get + +val mutableListFun: Function1, MutableList> + field = local fun (l: MutableList): MutableList { + return CHECK_NOT_NULL(arg0 = null) + } + + get + +val funWithIn: Function1, Unit> + field = local fun (x: Comparable) { + } + + get + +val extensionFun: @ExtensionFunctionType Function1 + field = local fun Any.() { + } + + get + +val extensionWithArgFun: @ExtensionFunctionType Function2 + field = local fun Long.(x: Any): Date { + return Date() + } + + get diff --git a/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.ir.txt b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.ir.txt new file mode 100644 index 00000000000..b015b9465e4 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.ir.txt @@ -0,0 +1,110 @@ +FILE fqName: fileName:/functionLiteralGenericSignature.kt + PROPERTY name:unitFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:unitFun type:kotlin.Function0 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .unitFun' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function0 + correspondingProperty: PROPERTY name:unitFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function0 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:unitFun type:kotlin.Function0 visibility:private [final,static]' type=kotlin.Function0 origin=null + PROPERTY name:intFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:intFun type:kotlin.Function0 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .intFun' + CONST Int type=kotlin.Int value=42 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function0 + correspondingProperty: PROPERTY name:intFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function0 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:intFun type:kotlin.Function0 visibility:private [final,static]' type=kotlin.Function0 origin=null + PROPERTY name:stringParamFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:stringParamFun type:kotlin.Function1 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:kotlin.String) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (x: kotlin.String): kotlin.Unit declared in .stringParamFun' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1 + correspondingProperty: PROPERTY name:stringParamFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:stringParamFun type:kotlin.Function1 visibility:private [final,static]' type=kotlin.Function1 origin=null + PROPERTY name:listFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:listFun type:kotlin.Function1, kotlin.collections.List> visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1, kotlin.collections.List> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (l:kotlin.collections.List) returnType:kotlin.collections.List + VALUE_PARAMETER name:l index:0 type:kotlin.collections.List + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (l: kotlin.collections.List): kotlin.collections.List declared in .listFun' + GET_VAR 'l: kotlin.collections.List declared in .listFun.' type=kotlin.collections.List origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1, kotlin.collections.List> + correspondingProperty: PROPERTY name:listFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1, kotlin.collections.List> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:listFun type:kotlin.Function1, kotlin.collections.List> visibility:private [final,static]' type=kotlin.Function1, kotlin.collections.List> origin=null + PROPERTY name:mutableListFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:mutableListFun type:kotlin.Function1, kotlin.collections.MutableList> visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1, kotlin.collections.MutableList> origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> (l:kotlin.collections.MutableList) returnType:kotlin.collections.MutableList + VALUE_PARAMETER name:l index:0 type:kotlin.collections.MutableList + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (l: kotlin.collections.MutableList): kotlin.collections.MutableList declared in .mutableListFun' + CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.Nothing origin=EXCLEXCL + : kotlin.Nothing + arg0: CONST Null type=kotlin.Nothing? value=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1, kotlin.collections.MutableList> + correspondingProperty: PROPERTY name:mutableListFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1, kotlin.collections.MutableList> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:mutableListFun type:kotlin.Function1, kotlin.collections.MutableList> visibility:private [final,static]' type=kotlin.Function1, kotlin.collections.MutableList> origin=null + PROPERTY name:funWithIn visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:funWithIn type:kotlin.Function1, kotlin.Unit> visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=kotlin.Function1, kotlin.Unit> origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> (x:kotlin.Comparable) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.Comparable + BLOCK_BODY + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function1, kotlin.Unit> + correspondingProperty: PROPERTY name:funWithIn visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function1, kotlin.Unit> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:funWithIn type:kotlin.Function1, kotlin.Unit> visibility:private [final,static]' type=kotlin.Function1, kotlin.Unit> origin=null + PROPERTY name:extensionFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:extensionFun type:@[ExtensionFunctionType] kotlin.Function1 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> ($receiver:kotlin.Any) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:kotlin.Any + BLOCK_BODY + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:@[ExtensionFunctionType] kotlin.Function1 + correspondingProperty: PROPERTY name:extensionFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): @[ExtensionFunctionType] kotlin.Function1 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:extensionFun type:@[ExtensionFunctionType] kotlin.Function1 visibility:private [final,static]' type=@[ExtensionFunctionType] kotlin.Function1 origin=null + PROPERTY name:extensionWithArgFun visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:extensionWithArgFun type:@[ExtensionFunctionType] kotlin.Function2 visibility:private [final,static] + EXPRESSION_BODY + FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function2 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> ($receiver:kotlin.Long, x:kotlin.Any) returnType:java.util.Date + $receiver: VALUE_PARAMETER name: type:kotlin.Long + VALUE_PARAMETER name:x index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (x: kotlin.Any): java.util.Date declared in .extensionWithArgFun' + CONSTRUCTOR_CALL 'public constructor () declared in java.util.Date' type=java.util.Date origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:@[ExtensionFunctionType] kotlin.Function2 + correspondingProperty: PROPERTY name:extensionWithArgFun visibility:public modality:FINAL [val] + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): @[ExtensionFunctionType] kotlin.Function2 declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:extensionWithArgFun type:@[ExtensionFunctionType] kotlin.Function2 visibility:private [final,static]' type=@[ExtensionFunctionType] kotlin.Function2 origin=null diff --git a/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt new file mode 100644 index 00000000000..5ef3919dde1 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt @@ -0,0 +1,11 @@ +import java.util.Date + +val unitFun = { } +val intFun = { 42 } +val stringParamFun = { x: String -> } +val listFun = { l: List -> l } +val mutableListFun = fun (l: MutableList): MutableList = null!! +val funWithIn = fun (x: Comparable) {} + +val extensionFun = fun Any.() {} +val extensionWithArgFun = fun Long.(x: Any): Date = Date() diff --git a/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt.txt b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt.txt new file mode 100644 index 00000000000..aa648f6b93f --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt.txt @@ -0,0 +1,53 @@ +val unitFun: Function0 + field = local fun () { + return Unit + } + + get + +val intFun: Function0 + field = local fun (): Int { + return 42 + } + + get + +val stringParamFun: Function1 + field = local fun (x: String) { + return Unit + } + + get + +val listFun: Function1, List> + field = local fun (l: List): List { + return l + } + + get + +val mutableListFun: Function1, MutableList> + field = local fun (l: MutableList): MutableList { + return CHECK_NOT_NULL(arg0 = null) + } + + get + +val funWithIn: Function1, Unit> + field = local fun (x: Comparable) { + } + + get + +val extensionFun: @ExtensionFunctionType Function1 + field = local fun Any.() { + } + + get + +val extensionWithArgFun: @ExtensionFunctionType Function2 + field = local fun Long.(x: Any): Date { + return Date() + } + + get diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 82095560154..a608c19ebda 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -2494,6 +2494,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/firProblems/FlushFromAnonymous.kt"); } + @Test + @TestMetadata("functionLiteralGenericSignature.kt") + public void testFunctionLiteralGenericSignature() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt"); + } + @Test @TestMetadata("ImplicitReceiverStack.kt") public void testImplicitReceiverStack() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java index b3f7338408e..b2e8ec3943a 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java @@ -1857,6 +1857,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/firProblems/FlushFromAnonymous.kt"); } + @TestMetadata("functionLiteralGenericSignature.kt") + public void testFunctionLiteralGenericSignature() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/functionLiteralGenericSignature.kt"); + } + @TestMetadata("ImplicitReceiverStack.kt") public void testImplicitReceiverStack() throws Exception { runTest("compiler/testData/ir/irText/firProblems/ImplicitReceiverStack.kt");