mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Fix: extract directly exposed fields with static modifier
This commit is contained in:
@@ -1262,13 +1262,13 @@ open class KotlinFileExtractor(
|
|||||||
DeclarationStackAdjuster(f).use {
|
DeclarationStackAdjuster(f).use {
|
||||||
val fNameSuffix = getExtensionReceiverType(f)?.let { it.classFqName?.asString()?.replace(".", "$$") } ?: ""
|
val fNameSuffix = getExtensionReceiverType(f)?.let { it.classFqName?.asString()?.replace(".", "$$") } ?: ""
|
||||||
val extractType = if (isAnnotationClassField(f)) kClassToJavaClass(f.type) else f.type
|
val extractType = if (isAnnotationClassField(f)) kClassToJavaClass(f.type) else f.type
|
||||||
return extractField(useField(f), "${f.name.asString()}$fNameSuffix", extractType, parentId, tw.getLocation(f), f.visibility, f, isExternalDeclaration(f), f.isFinal)
|
return extractField(useField(f), "${f.name.asString()}$fNameSuffix", extractType, parentId, tw.getLocation(f), f.visibility, f, isExternalDeclaration(f), f.isFinal, isDirectlyExposedCompanionObjectField(f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun extractField(id: Label<out DbField>, name: String, type: IrType, parentId: Label<out DbReftype>, locId: Label<DbLocation>, visibility: DescriptorVisibility, errorElement: IrElement, isExternalDeclaration: Boolean, isFinal: Boolean): Label<out DbField> {
|
private fun extractField(id: Label<out DbField>, name: String, type: IrType, parentId: Label<out DbReftype>, locId: Label<DbLocation>, visibility: DescriptorVisibility, errorElement: IrElement, isExternalDeclaration: Boolean, isFinal: Boolean, isStatic: Boolean): Label<out DbField> {
|
||||||
val t = useType(type)
|
val t = useType(type)
|
||||||
tw.writeFields(id, name, t.javaResult.id, parentId, id)
|
tw.writeFields(id, name, t.javaResult.id, parentId, id)
|
||||||
tw.writeFieldsKotlinType(id, t.kotlinResult.id)
|
tw.writeFieldsKotlinType(id, t.kotlinResult.id)
|
||||||
@@ -1278,6 +1278,9 @@ open class KotlinFileExtractor(
|
|||||||
if (isFinal) {
|
if (isFinal) {
|
||||||
addModifiers(id, "final")
|
addModifiers(id, "final")
|
||||||
}
|
}
|
||||||
|
if (isStatic) {
|
||||||
|
addModifiers(id, "static")
|
||||||
|
}
|
||||||
|
|
||||||
if (!isExternalDeclaration) {
|
if (!isExternalDeclaration) {
|
||||||
val fieldDeclarationId = tw.getFreshIdLabel<DbFielddecl>()
|
val fieldDeclarationId = tw.getFreshIdLabel<DbFielddecl>()
|
||||||
@@ -4209,12 +4212,12 @@ open class KotlinFileExtractor(
|
|||||||
val firstAssignmentStmtIdx = 1
|
val firstAssignmentStmtIdx = 1
|
||||||
|
|
||||||
if (dispatchReceiverInfo != null) {
|
if (dispatchReceiverInfo != null) {
|
||||||
extractField(dispatchReceiverInfo.field, "<dispatchReceiver>", dispatchReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true)
|
extractField(dispatchReceiverInfo.field, "<dispatchReceiver>", dispatchReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true, isStatic = false)
|
||||||
extractParameterToFieldAssignmentInConstructor("<dispatchReceiver>", dispatchReceiverInfo.type, dispatchReceiverInfo.field, 0 + dispatchReceiverInfo.indexOffset, firstAssignmentStmtIdx + dispatchReceiverInfo.indexOffset)
|
extractParameterToFieldAssignmentInConstructor("<dispatchReceiver>", dispatchReceiverInfo.type, dispatchReceiverInfo.field, 0 + dispatchReceiverInfo.indexOffset, firstAssignmentStmtIdx + dispatchReceiverInfo.indexOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extensionReceiverInfo != null) {
|
if (extensionReceiverInfo != null) {
|
||||||
extractField(extensionReceiverInfo.field, "<extensionReceiver>", extensionReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true)
|
extractField(extensionReceiverInfo.field, "<extensionReceiver>", extensionReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true, isStatic = false)
|
||||||
extractParameterToFieldAssignmentInConstructor( "<extensionReceiver>", extensionReceiverInfo.type, extensionReceiverInfo.field, 0 + extensionReceiverInfo.indexOffset, firstAssignmentStmtIdx + extensionReceiverInfo.indexOffset)
|
extractParameterToFieldAssignmentInConstructor( "<extensionReceiver>", extensionReceiverInfo.type, extensionReceiverInfo.field, 0 + extensionReceiverInfo.indexOffset, firstAssignmentStmtIdx + extensionReceiverInfo.indexOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5282,7 +5285,7 @@ open class KotlinFileExtractor(
|
|||||||
|
|
||||||
// add field
|
// add field
|
||||||
val fieldId = tw.getFreshIdLabel<DbField>()
|
val fieldId = tw.getFreshIdLabel<DbField>()
|
||||||
extractField(fieldId, "<fn>", functionType, classId, locId, DescriptorVisibilities.PRIVATE, e, isExternalDeclaration = false, isFinal = true)
|
extractField(fieldId, "<fn>", functionType, classId, locId, DescriptorVisibilities.PRIVATE, e, isExternalDeclaration = false, isFinal = true, isStatic = false)
|
||||||
|
|
||||||
// adjust constructor
|
// adjust constructor
|
||||||
helper.extractParameterToFieldAssignmentInConstructor("<fn>", functionType, fieldId, 0, 1)
|
helper.extractParameterToFieldAssignmentInConstructor("<fn>", functionType, fieldId, 0, 1)
|
||||||
|
|||||||
@@ -1649,7 +1649,7 @@ open class KotlinUsesExtractor(
|
|||||||
fun useValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>?): Label<out DbParam> =
|
fun useValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>?): Label<out DbParam> =
|
||||||
tw.getLabelFor(getValueParameterLabel(vp, parent))
|
tw.getLabelFor(getValueParameterLabel(vp, parent))
|
||||||
|
|
||||||
private fun isDirectlyExposedCompanionObjectField(f: IrField) =
|
private fun isDirectlyExposableCompanionObjectField(f: IrField) =
|
||||||
f.hasAnnotation(FqName("kotlin.jvm.JvmField")) ||
|
f.hasAnnotation(FqName("kotlin.jvm.JvmField")) ||
|
||||||
f.correspondingPropertySymbol?.owner?.let {
|
f.correspondingPropertySymbol?.owner?.let {
|
||||||
it.isConst || it.isLateinit
|
it.isConst || it.isLateinit
|
||||||
@@ -1657,12 +1657,14 @@ open class KotlinUsesExtractor(
|
|||||||
|
|
||||||
fun getFieldParent(f: IrField) =
|
fun getFieldParent(f: IrField) =
|
||||||
f.parentClassOrNull?.let {
|
f.parentClassOrNull?.let {
|
||||||
if (it.isCompanion && isDirectlyExposedCompanionObjectField(f))
|
if (it.isCompanion && isDirectlyExposableCompanionObjectField(f))
|
||||||
it.parent
|
it.parent
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
} ?: f.parent
|
} ?: f.parent
|
||||||
|
|
||||||
|
fun isDirectlyExposedCompanionObjectField(f: IrField) = getFieldParent(f) != f.parent
|
||||||
|
|
||||||
// Gets a field's corresponding property's extension receiver type, if any
|
// Gets a field's corresponding property's extension receiver type, if any
|
||||||
fun getExtensionReceiverType(f: IrField) =
|
fun getExtensionReceiverType(f: IrField) =
|
||||||
f.correspondingPropertySymbol?.owner?.let {
|
f.correspondingPropertySymbol?.owner?.let {
|
||||||
|
|||||||
Reference in New Issue
Block a user