Skip to content

Commit 4b825df

Browse files
committed
Kotlin: don't emit synthetic parameter names
The QL library already expects these to be missing in some cases and generates its own names when they are absent. Writing synthetic names to the database can produce inconsistencies if the true name is seen later.
1 parent 875776d commit 4b825df

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ open class KotlinFileExtractor(
507507
return FieldResult(instanceId, instanceName)
508508
}
509509

510+
@OptIn(ObsoleteDescriptorBasedAPI::class)
511+
private fun hasSynthesizedParameterNames(f: IrFunction) = f.descriptor.hasSynthesizedParameterNames()
512+
510513
private fun extractValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>, idx: Int, typeSubstitution: TypeSubstitution?, parentSourceDeclaration: Label<out DbCallable>, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, extractTypeAccess: Boolean, locOverride: Label<DbLocation>? = null): TypeResults {
511514
with("value parameter", vp) {
512515
val location = locOverride ?: getLocation(vp, classTypeArgsIncludingOuterClasses)
@@ -523,16 +526,19 @@ open class KotlinFileExtractor(
523526
if (extractTypeAccess) {
524527
extractTypeAccessRecursive(substitutedType, location, id, -1)
525528
}
526-
return extractValueParameter(id, substitutedType, vp.name.asString(), location, parent, idx, useValueParameter(vp, parentSourceDeclaration), vp.isVararg)
529+
val syntheticParameterNames = (vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true
530+
return extractValueParameter(id, substitutedType, vp.name.asString(), location, parent, idx, useValueParameter(vp, parentSourceDeclaration), vp.isVararg, syntheticParameterNames)
527531
}
528532
}
529533

530-
private fun extractValueParameter(id: Label<out DbParam>, t: IrType, name: String, locId: Label<DbLocation>, parent: Label<out DbCallable>, idx: Int, paramSourceDeclaration: Label<out DbParam>, isVararg: Boolean): TypeResults {
534+
private fun extractValueParameter(id: Label<out DbParam>, t: IrType, name: String, locId: Label<DbLocation>, parent: Label<out DbCallable>, idx: Int, paramSourceDeclaration: Label<out DbParam>, isVararg: Boolean, syntheticParameterNames: Boolean): TypeResults {
531535
val type = useType(t)
532536
tw.writeParams(id, type.javaResult.id, idx, parent, paramSourceDeclaration)
533537
tw.writeParamsKotlinType(id, type.kotlinResult.id)
534538
tw.writeHasLocation(id, locId)
535-
tw.writeParamName(id, name)
539+
if (!syntheticParameterNames) {
540+
tw.writeParamName(id, name)
541+
}
536542
if (isVararg) {
537543
tw.writeIsVarargsParam(id)
538544
}
@@ -2952,7 +2958,7 @@ open class KotlinFileExtractor(
29522958
stmtIdx: Int
29532959
) {
29542960
val paramId = tw.getFreshIdLabel<DbParam>()
2955-
val paramTypeRes = extractValueParameter(paramId, paramType, paramName, locId, ids.constructor, paramIdx, paramId, false)
2961+
val paramTypeRes = extractValueParameter(paramId, paramType, paramName, locId, ids.constructor, paramIdx, paramId, isVararg = false, syntheticParameterNames = false)
29562962

29572963
val assignmentStmtId = tw.getFreshIdLabel<DbExprstmt>()
29582964
tw.writeStmts_exprstmt(assignmentStmtId, ids.constructorBlock, stmtIdx, ids.constructor)
@@ -3588,7 +3594,7 @@ open class KotlinFileExtractor(
35883594

35893595
val parameters = parameterTypes.mapIndexed { idx, p ->
35903596
val paramId = tw.getFreshIdLabel<DbParam>()
3591-
val paramType = extractValueParameter(paramId, p, "a$idx", locId, methodId, idx, paramId, false)
3597+
val paramType = extractValueParameter(paramId, p, "a$idx", locId, methodId, idx, paramId, isVararg = false, syntheticParameterNames = false)
35923598

35933599
Pair(paramId, paramType)
35943600
}

0 commit comments

Comments
 (0)