Skip to content

Commit a32363d

Browse files
committed
Kotlin: Avoid giving a single class 2 compiler-generated kinds
1 parent 7863bc2 commit a32363d

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,14 +1507,15 @@ open class KotlinFileExtractor(
15071507
}
15081508
is IrFunction -> {
15091509
if (s.isLocalFunction()) {
1510-
val classId = extractGeneratedClass(s, listOf(pluginContext.irBuiltIns.anyType))
1510+
val compilerGeneratedKind = if (s.origin == IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE) {
1511+
CompilerGeneratedKinds.DECLARING_CLASSES_OF_ADAPTER_FUNCTIONS
1512+
} else {
1513+
null
1514+
}
1515+
val classId = extractGeneratedClass(s, listOf(pluginContext.irBuiltIns.anyType), compilerGeneratedKind = compilerGeneratedKind)
15111516
extractLocalTypeDeclStmt(classId, s, callable, parent, idx)
15121517
val ids = getLocallyVisibleFunctionLabels(s)
15131518
tw.writeKtLocalFunction(ids.function)
1514-
1515-
if (s.origin == IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE) {
1516-
tw.writeCompiler_generated(classId, CompilerGeneratedKinds.DECLARING_CLASSES_OF_ADAPTER_FUNCTIONS.kind)
1517-
}
15181519
} else {
15191520
logger.errorElement("Expected to find local function", s)
15201521
}
@@ -4685,7 +4686,7 @@ open class KotlinFileExtractor(
46854686
val baseClass = pluginContext.referenceClass(FqName("kotlin.jvm.internal.FunctionReference"))?.owner?.typeWith()
46864687
?: pluginContext.irBuiltIns.anyType
46874688

4688-
val classId = extractGeneratedClass(ids, listOf(baseClass, fnInterfaceType), locId, functionReferenceExpr, declarationParent, { it.valueParameters.size == 1 }) {
4689+
val classId = extractGeneratedClass(ids, listOf(baseClass, fnInterfaceType), locId, functionReferenceExpr, declarationParent, null, { it.valueParameters.size == 1 }) {
46894690
// The argument to FunctionReference's constructor is the function arity.
46904691
extractConstantInteger(type.arguments.size - 1, locId, it, 0, ids.constructor, it)
46914692
}
@@ -5389,14 +5390,15 @@ open class KotlinFileExtractor(
53895390
locId: Label<DbLocation>,
53905391
elementToReportOn: IrElement,
53915392
declarationParent: IrDeclarationParent,
5393+
compilerGeneratedKind: CompilerGeneratedKinds? = null,
53925394
superConstructorSelector: (IrFunction) -> Boolean = { it.valueParameters.isEmpty() },
5393-
extractSuperconstructorArgs: (Label<DbSuperconstructorinvocationstmt>) -> Unit = {}
5395+
extractSuperconstructorArgs: (Label<DbSuperconstructorinvocationstmt>) -> Unit = {},
53945396
): Label<out DbClass> {
53955397
// Write class
53965398
val id = ids.type.javaResult.id.cast<DbClass>()
53975399
val pkgId = extractPackage("")
53985400
tw.writeClasses(id, "", pkgId, id)
5399-
tw.writeCompiler_generated(id, CompilerGeneratedKinds.CALLABLE_CLASS.kind)
5401+
tw.writeCompiler_generated(id, (compilerGeneratedKind ?: CompilerGeneratedKinds.CALLABLE_CLASS).kind)
54005402
tw.writeHasLocation(id, locId)
54015403

54025404
// Extract constructor
@@ -5443,11 +5445,15 @@ open class KotlinFileExtractor(
54435445
/**
54445446
* Extracts the class around a local function or a lambda. The superclass must have a no-arg constructor.
54455447
*/
5446-
private fun extractGeneratedClass(localFunction: IrFunction, superTypes: List<IrType>) : Label<out DbClass> {
5448+
private fun extractGeneratedClass(
5449+
localFunction: IrFunction,
5450+
superTypes: List<IrType>,
5451+
compilerGeneratedKind: CompilerGeneratedKinds? = null
5452+
) : Label<out DbClass> {
54475453
with("generated class", localFunction) {
54485454
val ids = getLocallyVisibleFunctionLabels(localFunction)
54495455

5450-
val id = extractGeneratedClass(ids, superTypes, tw.getLocation(localFunction), localFunction, localFunction.parent)
5456+
val id = extractGeneratedClass(ids, superTypes, tw.getLocation(localFunction), localFunction, localFunction.parent, compilerGeneratedKind = compilerGeneratedKind)
54515457

54525458
// Extract local function as a member
54535459
extractFunction(localFunction, id, extractBody = true, extractMethodAndParameterTypeAccesses = true, null, listOf())

0 commit comments

Comments
 (0)