diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java index 4ee44af01be..8904d69198b 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java @@ -4344,6 +4344,11 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperPrivateFinalSyntheticField.kt"); } + @TestMetadata("samWrapperRawTypes.kt") + public void testSamWrapperRawTypes() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperRawTypes.kt"); + } + @TestMetadata("samWrapperSyntheticFlags.kt") public void testSamWrapperSyntheticFlags() throws Exception { runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperSyntheticFlags.kt"); diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt index e61d67505f3..7ff9ef0d343 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt @@ -66,6 +66,9 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) : abstract fun getSuperTypeForWrapper(typeOperand: IrType): IrType + protected open fun getWrappedFunctionType(klass: IrClass): IrType = + klass.defaultType + abstract val IrType.needEqualsHashCodeMethods: Boolean open val inInlineFunctionScope get() = allScopes.any { scope -> (scope.irElement as? IrFunction)?.isInline ?: false } @@ -161,7 +164,7 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) : context.ir.symbols.suspendFunctionN(superMethod.valueParameters.size + extensionReceiversCount).owner else context.ir.symbols.functionN(superMethod.valueParameters.size + extensionReceiversCount).owner - val wrappedFunctionType = wrappedFunctionClass.defaultType + val wrappedFunctionType = getWrappedFunctionType(wrappedFunctionClass) val subclass = context.irFactory.buildClass { name = wrapperName diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt index 99bf18b4b74..4fe1b149a87 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt @@ -51,11 +51,14 @@ class JvmBackendContext( irModuleFragment: IrModuleFragment, private val symbolTable: SymbolTable, val phaseConfig: PhaseConfig, - // If the JVM fqname of a class differs from what is implied by its parent, e.g. if it's a file class - // annotated with @JvmPackageName, the correct name is recorded here. - val classNameOverride: MutableMap, + val generatorExtensions: JvmGeneratorExtensions, val serializerFactory: MetadataSerializerFactory ) : CommonBackendContext { + // If the JVM fqname of a class differs from what is implied by its parent, e.g. if it's a file class + // annotated with @JvmPackageName, the correct name is recorded here. + val classNameOverride: MutableMap + get() = generatorExtensions.classNameOverride + override val transformedFunction: MutableMap get() = TODO("not implemented") diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt index df594690abb..ce9cea31c30 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt @@ -136,7 +136,7 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory ) { val context = JvmBackendContext( state, sourceManager, irModuleFragment.irBuiltins, irModuleFragment, - symbolTable, phaseConfig, extensions.classNameOverride, serializerFactory + symbolTable, phaseConfig, extensions, serializerFactory ) /* JvmBackendContext creates new unbound symbols, have to resolve them. */ ExternalDependenciesGenerator(symbolTable, irProviders, state.languageVersionSettings).generateUnboundSymbolsAsDependencies() diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt index 2eac9f92bc5..9124cc6d687 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt @@ -17,8 +17,8 @@ import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_FUNCTION_COMPLETION_PARAM import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_FUNCTION_CREATE_METHOD_NAME import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.DescriptorVisibilities +import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.builders.declarations.* import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt index 4cb77019a44..36d84583e63 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt @@ -17,8 +17,8 @@ import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.unboxInlineClass import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX import org.jetbrains.kotlin.config.JvmDefaultMode import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.DescriptorVisibilities +import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.deserialization.PLATFORM_DEPENDENT_ANNOTATION_FQ_NAME import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.types.* @@ -377,3 +378,19 @@ fun collectVisibleTypeParameters(scopeOwner: IrTypeParametersContainer): Set Int = { s -> 0 } + J.g(f) +} + +inline fun inlineFun() { + val f: (String?) -> Int = { s -> 0 } + J.g(f) +} + +// There should be no generic information in the SAM wrappers. +// 0 declaration: void \(kotlin.jvm.functions.Function1<.*, .*>\) +// 0 declaration: function extends kotlin.jvm.functions.Function1<.*, .*> +// 2 private final synthetic Lkotlin/jvm/functions/Function1; function +// 2 \(Lkotlin/jvm/functions/Function1;\)V \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 67793556522..45161e66415 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -4416,6 +4416,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperPrivateFinalSyntheticField.kt"); } + @TestMetadata("samWrapperRawTypes.kt") + public void testSamWrapperRawTypes() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperRawTypes.kt"); + } + @TestMetadata("samWrapperSyntheticFlags.kt") public void testSamWrapperSyntheticFlags() throws Exception { runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperSyntheticFlags.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index 8d1fdfaef6b..65d8047651a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -4344,6 +4344,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperPrivateFinalSyntheticField.kt"); } + @TestMetadata("samWrapperRawTypes.kt") + public void testSamWrapperRawTypes() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperRawTypes.kt"); + } + @TestMetadata("samWrapperSyntheticFlags.kt") public void testSamWrapperSyntheticFlags() throws Exception { runTest("compiler/testData/codegen/bytecodeText/sam/samWrapperSyntheticFlags.kt");