From 49ae1b8d0149352a8b243e8072e6b868dcef8732 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Thu, 21 Dec 2023 13:16:33 +0100 Subject: [PATCH] [FIR2IR] Consolidate type approximation This commit gets rid of the redundant typeApproximatorConfiguration in Fir2IrTypeConverter and uses the type approximator for captured types instead of the manual approximation used before. This fixes the nullability of approximated captured types, which fixes a runtime error in WASM. This also brings K2 IR closer to K1 IR in one test. #KT-64261 Fixed --- ...LFirBlackBoxCodegenBasedTestGenerated.java | 6 ++ ...rsedBlackBoxCodegenBasedTestGenerated.java | 6 ++ .../kotlin/fir/backend/Fir2IrTypeConverter.kt | 28 +++----- ...LightTreeBlackBoxCodegenTestGenerated.java | 6 ++ ...hIrFakeOverrideGeneratorTestGenerated.java | 6 ++ .../FirPsiBlackBoxCodegenTestGenerated.java | 6 ++ .../types/TypeApproximatorConfiguration.kt | 1 + .../starProjectionLambdaNullReturn.fir.ir.txt | 68 +++++++++++++++++++ .../fir/starProjectionLambdaNullReturn.ir.txt | 68 +++++++++++++++++++ .../box/fir/starProjectionLambdaNullReturn.kt | 21 ++++++ .../types/genericFunWithStar.fir.ir.txt | 2 +- .../types/genericFunWithStar.fir.kt.txt | 2 +- .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++ ...kBoxCodegenWithIrInlinerTestGenerated.java | 6 ++ .../LightAnalysisModeTestGenerated.java | 5 ++ .../fir/FirJsCodegenBoxTestGenerated.java | 6 ++ .../fir/FirJsES6CodegenBoxTestGenerated.java | 6 ++ .../test/ir/IrJsCodegenBoxTestGenerated.java | 6 ++ .../ir/IrJsES6CodegenBoxTestGenerated.java | 6 ++ .../FirNativeCodegenBoxTestGenerated.java | 6 ++ .../FirNativeCodegenBoxTestNoPLGenerated.java | 6 ++ .../NativeCodegenBoxTestGenerated.java | 6 ++ .../NativeCodegenBoxTestNoPLGenerated.java | 6 ++ .../test/FirWasmCodegenBoxTestGenerated.java | 6 ++ .../test/K1WasmCodegenBoxTestGenerated.java | 6 ++ 26 files changed, 281 insertions(+), 22 deletions(-) create mode 100644 compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.fir.ir.txt create mode 100644 compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.ir.txt create mode 100644 compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java index 0b9cce330ab..d1d9e4f41b2 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java @@ -20186,6 +20186,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java index 19c04b1aedb..dfda0e4885d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java @@ -20186,6 +20186,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt index 79349cd0bfc..02a0d673bea 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.backend import org.jetbrains.kotlin.fir.declarations.getAnnotationsByClassId import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.unexpandedConeClassLikeType -import org.jetbrains.kotlin.fir.languageVersionSettings import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor import org.jetbrains.kotlin.fir.resolve.toSymbol @@ -78,17 +77,6 @@ class Fir2IrTypeConverter( private val capturedTypeCache = mutableMapOf() private val errorTypeForCapturedTypeStub by lazy { createErrorType() } - private val typeApproximator = ConeTypeApproximator(session.typeContext, session.languageVersionSettings) - - private val typeApproximatorConfiguration = - object : TypeApproximatorConfiguration.AllFlexibleSameValue() { - override val allFlexible: Boolean get() = true - override val errorType: Boolean get() = true - override val integerLiteralConstantType: Boolean get() = true - override val integerConstantOperatorType: Boolean get() = true - override val intersectionTypesInContravariantPositions: Boolean get() = true - } - fun FirTypeRef.toIrType(typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT): IrType { capturedTypeCache.clear() return when (this) { @@ -216,11 +204,13 @@ class Fir2IrTypeConverter( val cached = capturedTypeCache[this] if (cached == null) { capturedTypeCache[this] = errorTypeForCapturedTypeStub - val supertypes = constructor.supertypes!! - val approximation = supertypes.find { - it == (constructor.projection as? ConeKotlinTypeProjection)?.type - } ?: supertypes.first() - val irType = approximation.toIrType(typeOrigin) + val irType = this.approximateForIrOrSelf().toIrType( + typeOrigin, + annotations, + hasFlexibleNullability = hasFlexibleNullability, + hasFlexibleMutability = hasFlexibleMutability, + addRawTypeAnnotation = addRawTypeAnnotation + ) capturedTypeCache[this] = irType irType } else { @@ -322,9 +312,7 @@ class Fir2IrTypeConverter( } else null } } - return substitutor.substituteOrSelf(type).let { - typeApproximator.approximateToSuperType(it, typeApproximatorConfiguration) ?: it - } + return substitutor.substituteOrSelf(type).approximateForIrOrSelf() } } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 8bbfa19e231..d7f9e506786 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -19861,6 +19861,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java index 9354d5ee416..1dcaaf9dc9e 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java @@ -19861,6 +19861,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 60ba0ec5d13..d5ad0920487 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -19861,6 +19861,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt index 72451d66a6c..8bea6625a4c 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/types/TypeApproximatorConfiguration.kt @@ -138,6 +138,7 @@ open class TypeApproximatorConfiguration { override val allFlexible: Boolean get() = true override val errorType: Boolean get() = true override val integerLiteralConstantType: Boolean get() = true + override val integerConstantOperatorType: Boolean get() = true override val intersectionTypesInContravariantPositions: Boolean get() = true } } diff --git a/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.fir.ir.txt b/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.fir.ir.txt new file mode 100644 index 00000000000..4fbdd0005a6 --- /dev/null +++ b/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.fir.ir.txt @@ -0,0 +1,68 @@ +FILE fqName: fileName:/starProjectionLambdaNullReturn.kt + CLASS INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I.I> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] reified:false + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.I.I>, func:kotlin.Function0.I?>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.I.I> + VALUE_PARAMETER name:func index:0 type:kotlin.Function0.I?> + 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 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 CLASS name:Impl modality:FINAL visibility:public superTypes:[.I.Impl>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Impl.Impl> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] reified:false + CONSTRUCTOR visibility:public <> () returnType:.Impl.Impl> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Impl modality:FINAL visibility:public superTypes:[.I.Impl>]' + FUN name:foo visibility:public modality:OPEN <> ($this:.Impl.Impl>, func:kotlin.Function0.Impl?>) returnType:kotlin.Unit + overridden: + public abstract fun foo (func: kotlin.Function0.I?>): kotlin.Unit declared in .I + $this: VALUE_PARAMETER name: type:.Impl.Impl> + VALUE_PARAMETER name:func index:0 type:kotlin.Function0.Impl?> + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=T of .Impl? origin=INVOKE + $this: GET_VAR 'func: kotlin.Function0.Impl?> declared in .Impl.foo' type=kotlin.Function0.Impl?> origin=VARIABLE_AS_FUNCTION + 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 declared in .I + $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 .I + $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 .I + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:foo visibility:public modality:FINAL <> ($receiver:.I<*>) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.I<*> + BLOCK_BODY + CALL 'public abstract fun foo (func: kotlin.Function0.I?>): kotlin.Unit declared in .I' type=kotlin.Unit origin=null + $this: GET_VAR ': .I<*> declared in .foo' type=.I<*> origin=null + func: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Any? + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Any? declared in .foo' + CONST Null type=kotlin.Nothing? value=null + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:foo type:.Impl [val] + CONSTRUCTOR_CALL 'public constructor () declared in .Impl' type=.Impl origin=null + : kotlin.String + CALL 'public final fun foo (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + $receiver: GET_VAR 'val foo: .Impl declared in .box' type=.Impl origin=null + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" diff --git a/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.ir.txt b/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.ir.txt new file mode 100644 index 00000000000..9c531d54ad4 --- /dev/null +++ b/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.ir.txt @@ -0,0 +1,68 @@ +FILE fqName: fileName:/starProjectionLambdaNullReturn.kt + CLASS INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I.I> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] reified:false + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.I.I>, func:kotlin.Function0.I?>) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.I.I> + VALUE_PARAMETER name:func index:0 type:kotlin.Function0.I?> + 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 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 CLASS name:Impl modality:FINAL visibility:public superTypes:[.I.Impl>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Impl.Impl> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] reified:false + CONSTRUCTOR visibility:public <> () returnType:.Impl.Impl> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Impl modality:FINAL visibility:public superTypes:[.I.Impl>]' + FUN name:foo visibility:public modality:OPEN <> ($this:.Impl.Impl>, func:kotlin.Function0.Impl?>) returnType:kotlin.Unit + overridden: + public abstract fun foo (func: kotlin.Function0.I?>): kotlin.Unit declared in .I + $this: VALUE_PARAMETER name: type:.Impl.Impl> + VALUE_PARAMETER name:func index:0 type:kotlin.Function0.Impl?> + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=T of .Impl? origin=INVOKE + $this: GET_VAR 'func: kotlin.Function0.Impl?> declared in .Impl.foo' type=kotlin.Function0.Impl?> origin=VARIABLE_AS_FUNCTION + 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 declared in .I + $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 .I + $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 .I + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:foo visibility:public modality:FINAL <> ($receiver:.I<*>) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.I<*> + BLOCK_BODY + CALL 'public abstract fun foo (func: kotlin.Function0.I?>): kotlin.Unit declared in .I' type=kotlin.Unit origin=null + $this: GET_VAR ': .I<*> declared in .foo' type=.I<*> origin=null + func: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing? + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Nothing? declared in .foo' + CONST Null type=kotlin.Nothing? value=null + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:foo type:.Impl [val] + CONSTRUCTOR_CALL 'public constructor () declared in .Impl' type=.Impl origin=null + : kotlin.String + CALL 'public final fun foo (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + $receiver: GET_VAR 'val foo: .Impl declared in .box' type=.Impl origin=null + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" diff --git a/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt b/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt new file mode 100644 index 00000000000..4bc2b4d1308 --- /dev/null +++ b/compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt @@ -0,0 +1,21 @@ +// ISSUE: KT-64261 +// DUMP_IR +interface I { + fun foo(func: () -> T?) +} + +class Impl : I { + override fun foo(func: () -> T?) { + func() + } +} + +fun I<*>.foo() { + foo { null } +} + +fun box(): String { + val foo = Impl() + foo.foo() + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt b/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt index 7a2fda40acf..ef5f0545c86 100644 --- a/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt +++ b/compiler/testData/ir/irText/types/genericFunWithStar.fir.ir.txt @@ -77,7 +77,7 @@ FILE fqName: fileName:/genericFunWithStar.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun bar (vararg serializers: .I<*>): .I<*> declared in .Box' CALL 'public abstract fun foo (tSerializer: .I.Box.foo>): .I<.Box.Box.foo>> declared in .Box' type=.I.Box<*>> origin=null - : .IFoo + : .IBase $this: GET_VAR ': .Box.Box> declared in .Box.bar' type=.Box.Box> origin=null tSerializer: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array declared in kotlin.Array' type=.I<*> origin=null $this: GET_VAR 'serializers: kotlin.Array.I<*>> declared in .Box.bar' type=kotlin.Array.I<*>> origin=null diff --git a/compiler/testData/ir/irText/types/genericFunWithStar.fir.kt.txt b/compiler/testData/ir/irText/types/genericFunWithStar.fir.kt.txt index 52137c9979c..5bc8a393b34 100644 --- a/compiler/testData/ir/irText/types/genericFunWithStar.fir.kt.txt +++ b/compiler/testData/ir/irText/types/genericFunWithStar.fir.kt.txt @@ -20,7 +20,7 @@ abstract class Box : IFoo, IBar where T : IFoo, T : IBar { abstract fun foo(tSerializer: I): I> where F : IFoo, F : IBar fun bar(vararg serializers: I<*>): I<*> { - return .foo(tSerializer = serializers.get(index = 0)) + return .foo(tSerializer = serializers.get(index = 0)) } } diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 64ca534f38c..8765a04393c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -18841,6 +18841,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index c26d9c9e8a6..5bf1f757eff 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -19861,6 +19861,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index d8dff69281f..7f6d3d93628 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -19861,6 +19861,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index ff16cc38978..d2ca6d75c3e 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16567,6 +16567,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/fir/StackOverflowInAnnotationLoader.kt"); } + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @TestMetadata("staticImportFromEnum.kt") public void testStaticImportFromEnum() throws Exception { runTest("compiler/testData/codegen/box/fir/staticImportFromEnum.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 9e22f06fbf3..45169eda965 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -14737,6 +14737,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java index 18c3e5f7e9f..6e073f9a3eb 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6CodegenBoxTestGenerated.java @@ -14737,6 +14737,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index e74fb3f1e28..c60dec0b172 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -14737,6 +14737,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index 8b186254871..a893366702c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -14737,6 +14737,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java index d0fc666c06b..40a14d7779c 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java @@ -16251,6 +16251,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java index 5df28a5e815..81d9b64be10 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java @@ -16627,6 +16627,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java index f437a5904b4..709299a8c85 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java @@ -15875,6 +15875,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java index a1bd74ea4a0..86c23e3d7f7 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java @@ -16252,6 +16252,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java index a9f9a9ebaa8..96f28d30b08 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java @@ -14713,6 +14713,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception { diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java index 15f37d580ce..7c12f10de7e 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java @@ -14713,6 +14713,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest runTest("compiler/testData/codegen/box/fir/smartCastToInvisibleClassMember.kt"); } + @Test + @TestMetadata("starProjectionLambdaNullReturn.kt") + public void testStarProjectionLambdaNullReturn() throws Exception { + runTest("compiler/testData/codegen/box/fir/starProjectionLambdaNullReturn.kt"); + } + @Test @TestMetadata("suppressedInvisibleReferenceQualifier.kt") public void testSuppressedInvisibleReferenceQualifier() throws Exception {