Skip to content

Commit 00f323c

Browse files
committed
Fix: extract directly exposed fields with static modifier
1 parent c68ac46 commit 00f323c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,13 @@ open class KotlinFileExtractor(
12621262
DeclarationStackAdjuster(f).use {
12631263
val fNameSuffix = getExtensionReceiverType(f)?.let { it.classFqName?.asString()?.replace(".", "$$") } ?: ""
12641264
val extractType = if (isAnnotationClassField(f)) kClassToJavaClass(f.type) else f.type
1265-
return extractField(useField(f), "${f.name.asString()}$fNameSuffix", extractType, parentId, tw.getLocation(f), f.visibility, f, isExternalDeclaration(f), f.isFinal)
1265+
return extractField(useField(f), "${f.name.asString()}$fNameSuffix", extractType, parentId, tw.getLocation(f), f.visibility, f, isExternalDeclaration(f), f.isFinal, isDirectlyExposedCompanionObjectField(f))
12661266
}
12671267
}
12681268
}
12691269

12701270

1271-
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> {
1271+
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> {
12721272
val t = useType(type)
12731273
tw.writeFields(id, name, t.javaResult.id, parentId, id)
12741274
tw.writeFieldsKotlinType(id, t.kotlinResult.id)
@@ -1278,6 +1278,9 @@ open class KotlinFileExtractor(
12781278
if (isFinal) {
12791279
addModifiers(id, "final")
12801280
}
1281+
if (isStatic) {
1282+
addModifiers(id, "static")
1283+
}
12811284

12821285
if (!isExternalDeclaration) {
12831286
val fieldDeclarationId = tw.getFreshIdLabel<DbFielddecl>()
@@ -4209,12 +4212,12 @@ open class KotlinFileExtractor(
42094212
val firstAssignmentStmtIdx = 1
42104213

42114214
if (dispatchReceiverInfo != null) {
4212-
extractField(dispatchReceiverInfo.field, "<dispatchReceiver>", dispatchReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true)
4215+
extractField(dispatchReceiverInfo.field, "<dispatchReceiver>", dispatchReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true, isStatic = false)
42134216
extractParameterToFieldAssignmentInConstructor("<dispatchReceiver>", dispatchReceiverInfo.type, dispatchReceiverInfo.field, 0 + dispatchReceiverInfo.indexOffset, firstAssignmentStmtIdx + dispatchReceiverInfo.indexOffset)
42144217
}
42154218

42164219
if (extensionReceiverInfo != null) {
4217-
extractField(extensionReceiverInfo.field, "<extensionReceiver>", extensionReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true)
4220+
extractField(extensionReceiverInfo.field, "<extensionReceiver>", extensionReceiverInfo.type, classId, locId, DescriptorVisibilities.PRIVATE, callableReferenceExpr, isExternalDeclaration = false, isFinal = true, isStatic = false)
42184221
extractParameterToFieldAssignmentInConstructor( "<extensionReceiver>", extensionReceiverInfo.type, extensionReceiverInfo.field, 0 + extensionReceiverInfo.indexOffset, firstAssignmentStmtIdx + extensionReceiverInfo.indexOffset)
42194222
}
42204223
}
@@ -5282,7 +5285,7 @@ open class KotlinFileExtractor(
52825285

52835286
// add field
52845287
val fieldId = tw.getFreshIdLabel<DbField>()
5285-
extractField(fieldId, "<fn>", functionType, classId, locId, DescriptorVisibilities.PRIVATE, e, isExternalDeclaration = false, isFinal = true)
5288+
extractField(fieldId, "<fn>", functionType, classId, locId, DescriptorVisibilities.PRIVATE, e, isExternalDeclaration = false, isFinal = true, isStatic = false)
52865289

52875290
// adjust constructor
52885291
helper.extractParameterToFieldAssignmentInConstructor("<fn>", functionType, fieldId, 0, 1)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,20 +1649,22 @@ open class KotlinUsesExtractor(
16491649
fun useValueParameter(vp: IrValueParameter, parent: Label<out DbCallable>?): Label<out DbParam> =
16501650
tw.getLabelFor(getValueParameterLabel(vp, parent))
16511651

1652-
private fun isDirectlyExposedCompanionObjectField(f: IrField) =
1652+
private fun isDirectlyExposableCompanionObjectField(f: IrField) =
16531653
f.hasAnnotation(FqName("kotlin.jvm.JvmField")) ||
16541654
f.correspondingPropertySymbol?.owner?.let {
16551655
it.isConst || it.isLateinit
16561656
} ?: false
16571657

16581658
fun getFieldParent(f: IrField) =
16591659
f.parentClassOrNull?.let {
1660-
if (it.isCompanion && isDirectlyExposedCompanionObjectField(f))
1660+
if (it.isCompanion && isDirectlyExposableCompanionObjectField(f))
16611661
it.parent
16621662
else
16631663
null
16641664
} ?: f.parent
16651665

1666+
fun isDirectlyExposedCompanionObjectField(f: IrField) = getFieldParent(f) != f.parent
1667+
16661668
// Gets a field's corresponding property's extension receiver type, if any
16671669
fun getExtensionReceiverType(f: IrField) =
16681670
f.correspondingPropertySymbol?.owner?.let {

0 commit comments

Comments
 (0)