diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 3df80ccb042..104d6713b71 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -13712,6 +13712,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/fir/ExtensionAlias.kt"); } + @Test + @TestMetadata("FakeOverrideBuilder.kt") + public void testFakeOverrideBuilder() throws Exception { + runTest("compiler/testData/codegen/box/fir/FakeOverrideBuilder.kt"); + } + @Test @TestMetadata("IrBuiltIns.kt") public void testIrBuiltIns() throws Exception { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 9e58d54636d..d1c4e41dcb1 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -1026,7 +1026,7 @@ class Fir2IrDeclarationStorage( val irFunction = fir.convertWithOffsets { startOffset, endOffset -> symbolTable.declareSimpleFunction(signature, { symbol }) { val isFakeOverride = - firFunctionSymbol is FirNamedFunctionSymbol && fir.isSubstitutionOverride && + firFunctionSymbol is FirNamedFunctionSymbol && fir.isSubstitutionOrIntersectionOverride && firFunctionSymbol.dispatchReceiverClassOrNull() != firFunctionSymbol.originalForSubstitutionOverride?.dispatchReceiverClassOrNull() Fir2IrLazySimpleFunction( diff --git a/compiler/testData/codegen/box/fir/FakeOverrideBuilder.kt b/compiler/testData/codegen/box/fir/FakeOverrideBuilder.kt new file mode 100644 index 00000000000..58d4b3c639e --- /dev/null +++ b/compiler/testData/codegen/box/fir/FakeOverrideBuilder.kt @@ -0,0 +1,59 @@ +// TARGET_BACKEND: JVM +// MODULE: lib +// FILE: FakeOverrideBuilder_lib.kt + +class IrPropertySymbolImpl : + IrBindableSymbolBase(), + IrPropertySymbol + +abstract class IrBindableSymbolBase : + IrBindableSymbol, IrSymbolBase() { + + private var _owner: B? = null + override val owner: B + get() = _owner ?: throw IllegalStateException("") + + override fun bind(owner: B) { + if (_owner == null) { + _owner = owner + } else { + throw IllegalStateException("") + } + } +} + +abstract class IrSymbolBase : IrSymbol + +interface IrPropertySymbol : IrBindableSymbol + +interface IrBindableSymbol : IrSymbol { + override val owner: B + + fun bind(owner: B) +} + +interface IrSymbol { + val owner: IrSymbolOwner +} + +interface IrSymbolOwner { + val symbol: IrSymbol +} + +class IrProperty(override val symbol: IrPropertySymbol, val name: String) : IrSymbolOwner + +// MODULE: main(lib) +// FILE: FakeOverrideBuilder_main.kt + +fun link(declaration: IrSymbolOwner) { + val tempSymbol = IrPropertySymbolImpl() + tempSymbol.bind(declaration as IrProperty) +} + +fun box(): String { + val symbol = IrPropertySymbolImpl() + val property = IrProperty(symbol, "OK") + symbol.bind(property) + link(property) + return symbol.owner.name +} diff --git a/compiler/testData/ir/irText/firProblems/MultiList.fir.txt b/compiler/testData/ir/irText/firProblems/MultiList.fir.txt index 02fffb889eb..e52739c3918 100644 --- a/compiler/testData/ir/irText/firProblems/MultiList.fir.txt +++ b/compiler/testData/ir/irText/firProblems/MultiList.fir.txt @@ -271,12 +271,12 @@ FILE fqName: fileName:/MultiList.kt FUN FAKE_OVERRIDE name:parallelStream visibility:public modality:OPEN <> ($this:java.util.Collection) returnType:@[FlexibleNullability] java.util.stream.Stream<.Some.SomeList>?> [fake_override] overridden: public open fun parallelStream (): @[FlexibleNullability] java.util.stream.Stream<.Some.MyList>?> [fake_override] declared in .MyList - public open fun parallelStream (): @[FlexibleNullability] java.util.stream.Stream<@[FlexibleNullability] E of java.util.ArrayList?> declared in java.util.ArrayList + public open fun parallelStream (): @[FlexibleNullability] java.util.stream.Stream<@[FlexibleNullability] E of java.util.ArrayList?> [fake_override] declared in java.util.ArrayList $this: VALUE_PARAMETER name: type:java.util.Collection FUN FAKE_OVERRIDE name:stream visibility:public modality:OPEN <> ($this:java.util.Collection) returnType:@[FlexibleNullability] java.util.stream.Stream<.Some.SomeList>?> [fake_override] overridden: public open fun stream (): @[FlexibleNullability] java.util.stream.Stream<.Some.MyList>?> [fake_override] declared in .MyList - public open fun stream (): @[FlexibleNullability] java.util.stream.Stream<@[FlexibleNullability] E of java.util.ArrayList?> declared in java.util.ArrayList + public open fun stream (): @[FlexibleNullability] java.util.stream.Stream<@[FlexibleNullability] E of java.util.ArrayList?> [fake_override] declared in java.util.ArrayList $this: VALUE_PARAMETER name: type:java.util.Collection FUN FAKE_OVERRIDE name:forEach visibility:public modality:OPEN <> ($this:java.lang.Iterable, p0:java.util.function.Consumer.Some.SomeList>?>?) returnType:kotlin.Unit [fake_override] overridden: @@ -287,18 +287,18 @@ FILE fqName: fileName:/MultiList.kt 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 - public open fun equals (p0: @[FlexibleNullability] kotlin.Any?): kotlin.Boolean [operator] declared in java.util.ArrayList + public open fun equals (p0: @[FlexibleNullability] kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in java.util.ArrayList $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 - public open fun hashCode (): kotlin.Int declared in java.util.ArrayList + public open fun hashCode (): kotlin.Int [fake_override] declared in java.util.ArrayList $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 - public open fun toString (): @[FlexibleNullability] kotlin.String declared in java.util.ArrayList + public open fun toString (): @[FlexibleNullability] kotlin.String [fake_override] declared in java.util.ArrayList $this: VALUE_PARAMETER name: type:kotlin.Any FUN FAKE_OVERRIDE name:elementData visibility:public/*package*/ modality:OPEN <> ($this:java.util.ArrayList, p0:kotlin.Int) returnType:.Some.SomeList>? [fake_override] overridden: @@ -493,18 +493,18 @@ FILE fqName: fileName:/MultiList.kt 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 - public open fun equals (p0: @[FlexibleNullability] kotlin.Any?): kotlin.Boolean [operator] declared in java.util.ArrayList + public open fun equals (p0: @[FlexibleNullability] kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in java.util.ArrayList $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 - public open fun hashCode (): kotlin.Int declared in java.util.ArrayList + public open fun hashCode (): kotlin.Int [fake_override] declared in java.util.ArrayList $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 - public open fun toString (): @[FlexibleNullability] kotlin.String declared in java.util.ArrayList + public open fun toString (): @[FlexibleNullability] kotlin.String [fake_override] declared in java.util.ArrayList $this: VALUE_PARAMETER name: type:kotlin.Any FUN FAKE_OVERRIDE name:elementData visibility:public/*package*/ modality:OPEN <> ($this:java.util.ArrayList, p0:kotlin.Int) returnType:.Some? [fake_override] overridden: diff --git a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt index 8fabbc89249..3e4c660222d 100644 --- a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt +++ b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt @@ -27,7 +27,7 @@ FILE fqName: fileName:/builtinMap.kt $receiver: VALUE_PARAMETER name: type:java.util.LinkedHashMap.plus?, V1 of .plus?> BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - CALL 'public open fun put (p0: @[FlexibleNullability] K of java.util.LinkedHashMap?, p1: @[FlexibleNullability] V of java.util.LinkedHashMap?): @[FlexibleNullability] V of java.util.LinkedHashMap? declared in java.util.LinkedHashMap' type=V1 of .plus? origin=null + CALL 'public open fun put (p0: @[FlexibleNullability] K of java.util.LinkedHashMap?, p1: @[FlexibleNullability] V of java.util.LinkedHashMap?): @[FlexibleNullability] V of java.util.LinkedHashMap? [fake_override] declared in java.util.LinkedHashMap' type=V1 of .plus? origin=null $this: GET_VAR ': java.util.LinkedHashMap.plus?, V1 of .plus?> declared in .plus.' type=java.util.LinkedHashMap.plus?, V1 of .plus?> origin=null p0: CALL 'public final fun (): A of kotlin.Pair declared in kotlin.Pair' type=K1 of .plus origin=GET_PROPERTY $this: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null 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 c4850eeb1a0..c7258387bd5 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 @@ -13712,6 +13712,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/fir/ExtensionAlias.kt"); } + @Test + @TestMetadata("FakeOverrideBuilder.kt") + public void testFakeOverrideBuilder() throws Exception { + runTest("compiler/testData/codegen/box/fir/FakeOverrideBuilder.kt"); + } + @Test @TestMetadata("IrBuiltIns.kt") public void testIrBuiltIns() 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 d2f59468085..3ab6cebe6fc 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 @@ -13712,6 +13712,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/ExtensionAlias.kt"); } + @Test + @TestMetadata("FakeOverrideBuilder.kt") + public void testFakeOverrideBuilder() throws Exception { + runTest("compiler/testData/codegen/box/fir/FakeOverrideBuilder.kt"); + } + @Test @TestMetadata("IrBuiltIns.kt") public void testIrBuiltIns() 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 cf690407596..b5ddf119858 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12052,6 +12052,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/fir/ExtensionAlias.kt"); } + @TestMetadata("FakeOverrideBuilder.kt") + public void testFakeOverrideBuilder() throws Exception { + runTest("compiler/testData/codegen/box/fir/FakeOverrideBuilder.kt"); + } + @TestMetadata("IrBuiltIns.kt") public void testIrBuiltIns() throws Exception { runTest("compiler/testData/codegen/box/fir/IrBuiltIns.kt");