diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt index 4ad353d8e98..43daf92ddc9 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt @@ -19,15 +19,19 @@ import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.backend.jvm.Fir2IrJvmSpecialAnnotationSymbolProvider import org.jetbrains.kotlin.fir.declarations.FirFile +import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyClass import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.ir.IrBuiltIns import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.KtDiagnosticReporterWithImplicitIrBasedContext import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrModuleFragment +import org.jetbrains.kotlin.ir.declarations.IrProperty +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase import org.jetbrains.kotlin.ir.overrides.IrFakeOverrideBuilder +import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI import org.jetbrains.kotlin.ir.types.IrTypeSystemContext import org.jetbrains.kotlin.ir.types.getClass import org.jetbrains.kotlin.ir.util.KotlinMangler @@ -117,7 +121,8 @@ fun FirResult.convertToIrAndActualize( // actualization separately. This should go away, after useIrFakeOverrideBuilder becomes // always enabled irActualizer?.actualizeClassifiers() - components.fakeOverrideBuilder.buildForAll(allIrModules) + val temporaryResolver = SpecialFakeOverrideSymbolsResolver(emptyMap()) + components.fakeOverrideBuilder.buildForAll(allIrModules, temporaryResolver) } val expectActualMap = irActualizer?.actualizeCallablesAndMergeModules() ?: emptyMap() if (components.configuration.useIrFakeOverrideBuilder) { @@ -132,15 +137,58 @@ fun FirResult.convertToIrAndActualize( return Fir2IrActualizedResult(irModuleFragment, components, pluginContext, actualizationResult) } -private fun IrFakeOverrideBuilder.buildForAll(modules: List) { + +private fun resolveOverridenSymbolsInLazyClass( + clazz: Fir2IrLazyClass, + resolver: SpecialFakeOverrideSymbolsResolver +) { + /* + * Eventually, we should be able to process lazy classes with the same code. + * + * Now we can't do this, because overriding by Java function is not supported correctly in IR builder. + * In most cases, nothing need to be done for lazy classes. For other cases, it is + * caller responsibility to handle them. + * + * Super-classes already have processed fake overrides at this moment. + * Also, all Fir2IrLazyClass super-classes are always platform classes, + * so it's valid to process it with empty expect-actual mapping. + * + * But this is still a hack, and should be removed within KT-64352 + */ + @OptIn(UnsafeDuringIrConstructionAPI::class) + for (declaration in clazz.declarations) { + when (declaration) { + is IrSimpleFunction -> { + declaration.overriddenSymbols = declaration.overriddenSymbols.map { resolver.getReferencedSimpleFunction(it) } + } + is IrProperty -> { + declaration.overriddenSymbols = declaration.overriddenSymbols.map { resolver.getReferencedProperty(it) } + declaration.getter?.let { getter -> + getter.overriddenSymbols = getter.overriddenSymbols.map { resolver.getReferencedSimpleFunction(it) } + } + declaration.setter?.let { setter -> + setter.overriddenSymbols = setter.overriddenSymbols.map { resolver.getReferencedSimpleFunction(it) } + } + } + } + } +} + +private fun IrFakeOverrideBuilder.buildForAll( + modules: List, + resolver: SpecialFakeOverrideSymbolsResolver +) { val builtFakeOverridesClasses = mutableSetOf() fun buildFakeOverrides(clazz: IrClass) { - if (clazz is IrLazyDeclarationBase) return if (!builtFakeOverridesClasses.add(clazz)) return for (c in clazz.superTypes) { c.getClass()?.let { buildFakeOverrides(it) } } - buildFakeOverridesForClass(clazz, false) + if (clazz is IrLazyDeclarationBase) { + resolveOverridenSymbolsInLazyClass(clazz as Fir2IrLazyClass, resolver) + } else { + buildFakeOverridesForClass(clazz, false) + } } class ClassVisitor : IrElementVisitorVoid { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java index 6fc1e374b6c..632c51050e5 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java @@ -468,6 +468,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI runTest("compiler/testData/ir/irText/declarations/extensionProperties.kt"); } + @Test + @TestMetadata("fakeOverrideModality.kt") + public void testFakeOverrideModality() throws Exception { + runTest("compiler/testData/ir/irText/declarations/fakeOverrideModality.kt"); + } + @Test @TestMetadata("fakeOverrides.kt") public void testFakeOverrides() throws Exception { @@ -540,6 +546,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI runTest("compiler/testData/ir/irText/declarations/kt52677.kt"); } + @Test + @TestMetadata("kt65236.kt") + public void testKt65236() throws Exception { + runTest("compiler/testData/ir/irText/declarations/kt65236.kt"); + } + @Test @TestMetadata("kt65432.kt") public void testKt65432() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java index 125813364dc..bd79d3b6720 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java @@ -468,6 +468,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest { runTest("compiler/testData/ir/irText/declarations/extensionProperties.kt"); } + @Test + @TestMetadata("fakeOverrideModality.kt") + public void testFakeOverrideModality() throws Exception { + runTest("compiler/testData/ir/irText/declarations/fakeOverrideModality.kt"); + } + @Test @TestMetadata("fakeOverrides.kt") public void testFakeOverrides() throws Exception { @@ -540,6 +546,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest { runTest("compiler/testData/ir/irText/declarations/kt52677.kt"); } + @Test + @TestMetadata("kt65236.kt") + public void testKt65236() throws Exception { + runTest("compiler/testData/ir/irText/declarations/kt65236.kt"); + } + @Test @TestMetadata("kt65432.kt") public void testKt65432() throws Exception { diff --git a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt index b42190cbc11..e4577e46ab1 100644 --- a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt +++ b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt @@ -1,6 +1,11 @@ // NATIVE error: static cache is broken: ld.gold invocation reported errors. Please try to disable compiler caches and rerun the build. // DONT_TARGET_EXACT_BACKEND: NATIVE // IGNORE_BACKEND: JS_IR, JS_IR_ES6 + +// KT-65416 +// IGNORE_BACKEND_K2: WASM + + // MODULE: lib // FILE: 2.kt abstract class A { diff --git a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/lateinitMemberPropertyDeclaration.kt b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/lateinitMemberPropertyDeclaration.kt index eae795e6c19..18afc35d20a 100644 --- a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/lateinitMemberPropertyDeclaration.kt +++ b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/lateinitMemberPropertyDeclaration.kt @@ -1,6 +1,10 @@ // NATIVE error: static cache is broken: ld.gold invocation reported errors. Please try to disable compiler caches and rerun the build. // DONT_TARGET_EXACT_BACKEND: NATIVE // IGNORE_BACKEND: JS_IR, JS_IR_ES6 + +// KT-65416 +// IGNORE_BACKEND_K2: WASM + // MODULE: lib // FILE: 2.kt abstract class A { diff --git a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionDeclaration.kt b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionDeclaration.kt index 08fa925e873..6d117ba6e22 100644 --- a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionDeclaration.kt +++ b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionDeclaration.kt @@ -1,6 +1,11 @@ // NATIVE error: static cache is broken: ld.gold invocation reported errors. Please try to disable compiler caches and rerun the build. // DONT_TARGET_EXACT_BACKEND: NATIVE // IGNORE_BACKEND: JS_IR, JS_IR_ES6 + +// KT-65416 +// IGNORE_BACKEND_K2: WASM + + // MODULE: lib // FILE: 2.kt abstract class A { diff --git a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionWithDefaultArgumentsDeclaration.kt b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionWithDefaultArgumentsDeclaration.kt index 90b8f9fb04b..8f7f0f26cf8 100644 --- a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionWithDefaultArgumentsDeclaration.kt +++ b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberFunctionWithDefaultArgumentsDeclaration.kt @@ -1,6 +1,11 @@ // NATIVE error: static cache is broken: ld.gold invocation reported errors. Please try to disable compiler caches and rerun the build. // DONT_TARGET_EXACT_BACKEND: NATIVE // IGNORE_BACKEND: JS_IR, JS_IR_ES6 + +// KT-65416 +// IGNORE_BACKEND_K2: WASM + + // MODULE: lib // FILE: 2.kt abstract class A { diff --git a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberPropertyDeclaration.kt b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberPropertyDeclaration.kt index b7b751085b3..7f5376e193c 100644 --- a/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberPropertyDeclaration.kt +++ b/compiler/testData/codegen/box/sameFileInSourceAndDependencies/memberPropertyDeclaration.kt @@ -1,6 +1,10 @@ // NATIVE error: static cache is broken: ld.gold invocation reported errors. Please try to disable compiler caches and rerun the build. // DONT_TARGET_EXACT_BACKEND: NATIVE // IGNORE_BACKEND: JS_IR, JS_IR_ES6 + +// KT-65416 +// IGNORE_BACKEND_K2: WASM + // MODULE: lib // FILE: 2.kt abstract class A { diff --git a/compiler/testData/ir/irText/declarations/fakeOverrideModality.ir.txt b/compiler/testData/ir/irText/declarations/fakeOverrideModality.ir.txt new file mode 100644 index 00000000000..98c733bd1a8 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/fakeOverrideModality.ir.txt @@ -0,0 +1,104 @@ +FILE fqName: fileName:/fakeOverrideModality.kt + CLASS CLASS name:Base modality:OPEN visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Base + CONSTRUCTOR visibility:public <> () returnType:.Base [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Base modality:OPEN 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 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:Child modality:FINAL visibility:public superTypes:[.Base] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Child + CONSTRUCTOR visibility:public <> () returnType:.Child [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .Base' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Child modality:FINAL visibility:public superTypes:[.Base]' + 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 .Base + $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 .Base + $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 .Base + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.I) returnType:.Base + $this: VALUE_PARAMETER name: type:.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:J modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.J + CONSTRUCTOR visibility:public <> () returnType:.J [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:J modality:ABSTRACT visibility:public superTypes:[kotlin.Any]' + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.J) returnType:.Child + $this: VALUE_PARAMETER name: type:.J + 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:A modality:ABSTRACT visibility:public superTypes:[.I; .J] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .J' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:ABSTRACT visibility:public superTypes:[.I; .J]' + FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:.J) returnType:.Child [fake_override] + overridden: + public abstract fun foo (): .Base declared in .I + public abstract fun foo (): .Child declared in .J + $this: VALUE_PARAMETER name: type:.J + 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 + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .J + $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 + public open fun hashCode (): kotlin.Int declared in .J + $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 + public open fun toString (): kotlin.String declared in .J + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/declarations/fakeOverrideModality.kt b/compiler/testData/ir/irText/declarations/fakeOverrideModality.kt new file mode 100644 index 00000000000..79203d222ce --- /dev/null +++ b/compiler/testData/ir/irText/declarations/fakeOverrideModality.kt @@ -0,0 +1,16 @@ +// FIR_IDENTICAL +// ENABLE_IR_FAKE_OVERRIDE_GENERATION +// TARGET_BACKEND: JVM + +open class Base +class Child: Base() + +interface I { + fun foo(): Base +} + +abstract class J { + abstract fun foo(): Child +} + +abstract class A : I, J() \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/fakeOverrideModality.kt.txt b/compiler/testData/ir/irText/declarations/fakeOverrideModality.kt.txt new file mode 100644 index 00000000000..8fc9d8b640a --- /dev/null +++ b/compiler/testData/ir/irText/declarations/fakeOverrideModality.kt.txt @@ -0,0 +1,42 @@ +open class Base { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +class Child : Base { + constructor() /* primary */ { + super/*Base*/() + /* () */ + + } + +} + +interface I { + abstract fun foo(): Base + +} + +abstract class J { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract fun foo(): Child + +} + +abstract class A : I, J { + constructor() /* primary */ { + super/*J*/() + /* () */ + + } + +} diff --git a/compiler/testData/ir/irText/declarations/fakeOverrideModality.sig.kt.txt b/compiler/testData/ir/irText/declarations/fakeOverrideModality.sig.kt.txt new file mode 100644 index 00000000000..b34a37f0b33 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/fakeOverrideModality.sig.kt.txt @@ -0,0 +1,71 @@ +// CHECK: +// Mangled name: A +// Public signature: /A|null[0] +abstract class A : J, I { + // CHECK: + // Mangled name: A#(){} + // Public signature: /A.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + + // CHECK JVM_IR: + // Mangled name: A#foo(){}Child + // Public signature: /A.foo|8517421086584195144[0] + // Public signature debug description: foo(){}Child + abstract /* fake */ override fun foo(): Child + +} + +// CHECK: +// Mangled name: Base +// Public signature: /Base|null[0] +open class Base { + // CHECK: + // Mangled name: Base#(){} + // Public signature: /Base.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + +} + +// CHECK: +// Mangled name: Child +// Public signature: /Child|null[0] +class Child : Base { + // CHECK: + // Mangled name: Child#(){} + // Public signature: /Child.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + +} + +// CHECK: +// Mangled name: J +// Public signature: /J|null[0] +abstract class J { + // CHECK: + // Mangled name: J#(){} + // Public signature: /J.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + + // CHECK JVM_IR: + // Mangled name: J#foo(){}Child + // Public signature: /J.foo|8517421086584195144[0] + // Public signature debug description: foo(){}Child + abstract fun foo(): Child + +} + +// CHECK: +// Mangled name: I +// Public signature: /I|null[0] +interface I { + // CHECK JVM_IR: + // Mangled name: I#foo(){}Base + // Public signature: /I.foo|-5590126600799232132[0] + // Public signature debug description: foo(){}Base + abstract fun foo(): Base + +} diff --git a/compiler/testData/ir/irText/declarations/kt65236.ir.txt b/compiler/testData/ir/irText/declarations/kt65236.ir.txt new file mode 100644 index 00000000000..b7fc8e7651f --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt65236.ir.txt @@ -0,0 +1,117 @@ +FILE fqName: fileName:/E.kt + CLASS INTERFACE name:II modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.II + FUN name:foo visibility:public modality:OPEN <> ($this:.II) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.II + BLOCK_BODY + 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 INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[.II] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I + FUN FAKE_OVERRIDE name:foo visibility:public modality:OPEN <> ($this:.II) returnType:kotlin.Unit [fake_override] + overridden: + public open fun foo (): kotlin.Unit declared in .II + $this: VALUE_PARAMETER name: type:.II + 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 .II + $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 .II + $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 .II + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:C modality:ABSTRACT visibility:public superTypes:[.I] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:ABSTRACT visibility:public superTypes:[.I]' + FUN name:foo visibility:public modality:ABSTRACT <> ($this:.C) returnType:kotlin.Unit + overridden: + public open fun foo (): kotlin.Unit declared in .I + $this: VALUE_PARAMETER name: type:.C + 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 + CLASS CLASS name:D modality:ABSTRACT visibility:public superTypes:[.C; .J] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.D + CONSTRUCTOR visibility:public <> () returnType:.D [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .C' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:D modality:ABSTRACT visibility:public superTypes:[.C; .J]' + FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:.C) returnType:kotlin.Unit [fake_override] + overridden: + public abstract fun foo (): kotlin.Unit declared in .C + public open fun foo (): kotlin.Unit declared in .J + $this: VALUE_PARAMETER name: type:.C + 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 .C + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .J + $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 .C + public open fun hashCode (): kotlin.Int declared in .J + $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 .C + public open fun toString (): kotlin.String declared in .J + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:E modality:FINAL visibility:public superTypes:[.D] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.E + CONSTRUCTOR visibility:public <> () returnType:.E [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .D' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:E modality:FINAL visibility:public superTypes:[.D]' + FUN name:foo visibility:public modality:OPEN <> ($this:.E) returnType:kotlin.Unit + overridden: + public abstract fun foo (): kotlin.Unit declared in .D + $this: VALUE_PARAMETER name: type:.E + BLOCK_BODY + 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 .D + $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 .D + $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 .D + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:foo visibility:public modality:FINAL <> (x:.I) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:.I + BLOCK_BODY + CALL 'public open fun foo (): kotlin.Unit declared in .I' type=kotlin.Unit origin=null + $this: GET_VAR 'x: .I declared in .foo' type=.I origin=null diff --git a/compiler/testData/ir/irText/declarations/kt65236.kt b/compiler/testData/ir/irText/declarations/kt65236.kt new file mode 100644 index 00000000000..0a10b54338a --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt65236.kt @@ -0,0 +1,32 @@ +// FIR_IDENTICAL +// ENABLE_IR_FAKE_OVERRIDE_GENERATION +// TARGET_BACKEND: JVM + +// FILE: J.java + +interface J extends I { + +} + +// FILE: E.kt + +interface II { + fun foo() {} +} + +interface I : II { +} + +abstract class C: I { + override abstract fun foo() +} + +abstract class D : C(), J {} + +class E : D() { + override fun foo() {} +} + +fun foo(x : I) { + x.foo() +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/kt65236.kt.txt b/compiler/testData/ir/irText/declarations/kt65236.kt.txt new file mode 100644 index 00000000000..0ff70e52cb5 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt65236.kt.txt @@ -0,0 +1,44 @@ +interface II { + fun foo() { + } + +} + +interface I : II { +} + +abstract class C : I { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract override fun foo() + +} + +abstract class D : C, J { + constructor() /* primary */ { + super/*C*/() + /* () */ + + } + +} + +class E : D { + constructor() /* primary */ { + super/*D*/() + /* () */ + + } + + override fun foo() { + } + +} + +fun foo(x: I) { + x.foo() +} diff --git a/compiler/testData/ir/irText/declarations/kt65236.sig.kt.txt b/compiler/testData/ir/irText/declarations/kt65236.sig.kt.txt new file mode 100644 index 00000000000..d20defb086e --- /dev/null +++ b/compiler/testData/ir/irText/declarations/kt65236.sig.kt.txt @@ -0,0 +1,83 @@ +// CHECK: +// Mangled name: C +// Public signature: /C|null[0] +abstract class C : I { + // CHECK: + // Mangled name: C#(){} + // Public signature: /C.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + + // CHECK: + // Mangled name: C#foo(){} + // Public signature: /C.foo|-1041209573719867811[0] + // Public signature debug description: foo(){} + abstract override fun foo(): Unit + +} + +// CHECK: +// Mangled name: D +// Public signature: /D|null[0] +abstract class D : C, J { + // CHECK: + // Mangled name: D#(){} + // Public signature: /D.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + + // CHECK: + // Mangled name: D#foo(){} + // Public signature: /D.foo|-1041209573719867811[0] + // Public signature debug description: foo(){} + abstract /* fake */ override fun foo(): Unit + +} + +// CHECK: +// Mangled name: E +// Public signature: /E|null[0] +class E : D { + // CHECK: + // Mangled name: E#(){} + // Public signature: /E.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + + // CHECK: + // Mangled name: E#foo(){} + // Public signature: /E.foo|-1041209573719867811[0] + // Public signature debug description: foo(){} + override fun foo(): Unit + +} + +// CHECK: +// Mangled name: I +// Public signature: /I|null[0] +interface I : II { + // CHECK: + // Mangled name: I#foo(){} + // Public signature: /I.foo|-1041209573719867811[0] + // Public signature debug description: foo(){} + /* fake */ override fun foo(): Unit + +} + +// CHECK: +// Mangled name: II +// Public signature: /II|null[0] +interface II { + // CHECK: + // Mangled name: II#foo(){} + // Public signature: /II.foo|-1041209573719867811[0] + // Public signature debug description: foo(){} + fun foo(): Unit + +} + +// CHECK: +// Mangled name: #foo(I){} +// Public signature: /foo|-4109751996049019888[0] +// Public signature debug description: foo(I){} +fun foo(x: I): Unit diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java index 70c342ace24..2236249f9f6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java @@ -468,6 +468,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest runTest("compiler/testData/ir/irText/declarations/extensionProperties.kt"); } + @Test + @TestMetadata("fakeOverrideModality.kt") + public void testFakeOverrideModality() throws Exception { + runTest("compiler/testData/ir/irText/declarations/fakeOverrideModality.kt"); + } + @Test @TestMetadata("fakeOverrides.kt") public void testFakeOverrides() throws Exception { @@ -540,6 +546,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest runTest("compiler/testData/ir/irText/declarations/kt52677.kt"); } + @Test + @TestMetadata("kt65236.kt") + public void testKt65236() throws Exception { + runTest("compiler/testData/ir/irText/declarations/kt65236.kt"); + } + @Test @TestMetadata("kt65432.kt") public void testKt65432() throws Exception {