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.
This commit is contained in:
Chris Smowton
2022-06-20 19:18:19 +01:00
parent 875776d91d
commit 4b825df60c

View File

@@ -507,6 +507,9 @@ open class KotlinFileExtractor(
return FieldResult(instanceId, instanceName) return FieldResult(instanceId, instanceName)
} }
@OptIn(ObsoleteDescriptorBasedAPI::class)
private fun hasSynthesizedParameterNames(f: IrFunction) = f.descriptor.hasSynthesizedParameterNames()
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 { 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 {
with("value parameter", vp) { with("value parameter", vp) {
val location = locOverride ?: getLocation(vp, classTypeArgsIncludingOuterClasses) val location = locOverride ?: getLocation(vp, classTypeArgsIncludingOuterClasses)
@@ -523,16 +526,19 @@ open class KotlinFileExtractor(
if (extractTypeAccess) { if (extractTypeAccess) {
extractTypeAccessRecursive(substitutedType, location, id, -1) extractTypeAccessRecursive(substitutedType, location, id, -1)
} }
return extractValueParameter(id, substitutedType, vp.name.asString(), location, parent, idx, useValueParameter(vp, parentSourceDeclaration), vp.isVararg) val syntheticParameterNames = (vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true
return extractValueParameter(id, substitutedType, vp.name.asString(), location, parent, idx, useValueParameter(vp, parentSourceDeclaration), vp.isVararg, syntheticParameterNames)
} }
} }
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 { 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 {
val type = useType(t) val type = useType(t)
tw.writeParams(id, type.javaResult.id, idx, parent, paramSourceDeclaration) tw.writeParams(id, type.javaResult.id, idx, parent, paramSourceDeclaration)
tw.writeParamsKotlinType(id, type.kotlinResult.id) tw.writeParamsKotlinType(id, type.kotlinResult.id)
tw.writeHasLocation(id, locId) tw.writeHasLocation(id, locId)
tw.writeParamName(id, name) if (!syntheticParameterNames) {
tw.writeParamName(id, name)
}
if (isVararg) { if (isVararg) {
tw.writeIsVarargsParam(id) tw.writeIsVarargsParam(id)
} }
@@ -2952,7 +2958,7 @@ open class KotlinFileExtractor(
stmtIdx: Int stmtIdx: Int
) { ) {
val paramId = tw.getFreshIdLabel<DbParam>() val paramId = tw.getFreshIdLabel<DbParam>()
val paramTypeRes = extractValueParameter(paramId, paramType, paramName, locId, ids.constructor, paramIdx, paramId, false) val paramTypeRes = extractValueParameter(paramId, paramType, paramName, locId, ids.constructor, paramIdx, paramId, isVararg = false, syntheticParameterNames = false)
val assignmentStmtId = tw.getFreshIdLabel<DbExprstmt>() val assignmentStmtId = tw.getFreshIdLabel<DbExprstmt>()
tw.writeStmts_exprstmt(assignmentStmtId, ids.constructorBlock, stmtIdx, ids.constructor) tw.writeStmts_exprstmt(assignmentStmtId, ids.constructorBlock, stmtIdx, ids.constructor)
@@ -3588,7 +3594,7 @@ open class KotlinFileExtractor(
val parameters = parameterTypes.mapIndexed { idx, p -> val parameters = parameterTypes.mapIndexed { idx, p ->
val paramId = tw.getFreshIdLabel<DbParam>() val paramId = tw.getFreshIdLabel<DbParam>()
val paramType = extractValueParameter(paramId, p, "a$idx", locId, methodId, idx, paramId, false) val paramType = extractValueParameter(paramId, p, "a$idx", locId, methodId, idx, paramId, isVararg = false, syntheticParameterNames = false)
Pair(paramId, paramType) Pair(paramId, paramType)
} }