Skip to content

Commit a791262

Browse files
committed
Override modality when needed
In particular when generating an implementation based on an abstract prototype, the result is final, and an interface forwarder is open / Java's default modality.
1 parent 045e3a2 commit a791262

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ open class KotlinFileExtractor(
891891
f.realOverrideTarget.let { it != f && (it as? IrSimpleFunction)?.modality != Modality.ABSTRACT && isKotlinDefinedInterface(it.parentClassOrNull) }
892892

893893
private fun makeInterfaceForwarder(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, extractMethodAndParameterTypeAccesses: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
894-
forceExtractFunction(f, parentId, extractBody = false, extractMethodAndParameterTypeAccesses, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = OverriddenFunctionAttributes(visibility = DescriptorVisibilities.PUBLIC)).also { functionId ->
894+
forceExtractFunction(f, parentId, extractBody = false, extractMethodAndParameterTypeAccesses, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = OverriddenFunctionAttributes(visibility = DescriptorVisibilities.PUBLIC, modality = Modality.OPEN)).also { functionId ->
895895
tw.writeCompiler_generated(functionId, CompilerGeneratedKinds.INTERFACE_FORWARDER.kind)
896896
if (extractBody) {
897897
val realFunctionLocId = tw.getLocation(f)
@@ -1244,7 +1244,7 @@ open class KotlinFileExtractor(
12441244
addModifiers(id, "suspend")
12451245
}
12461246
if (f.symbol !is IrConstructorSymbol) {
1247-
when((f as? IrSimpleFunction)?.modality) {
1247+
when(overriddenAttributes?.modality ?: (f as? IrSimpleFunction)?.modality) {
12481248
Modality.ABSTRACT -> addModifiers(id, "abstract")
12491249
Modality.FINAL -> addModifiers(id, "final")
12501250
else -> Unit
@@ -5311,7 +5311,7 @@ open class KotlinFileExtractor(
53115311
// we would need to compose generic type substitutions -- for example, if we're implementing
53125312
// T UnaryOperator<T>.apply(T t) here, we would need to compose substitutions so we can implement
53135313
// the real underlying R Function<T, R>.apply(T t).
5314-
forceExtractFunction(samMember, classId, extractBody = false, extractMethodAndParameterTypeAccesses = true, typeSub, classTypeArgs, overriddenAttributes = OverriddenFunctionAttributes(id = ids.function, sourceLoc = tw.getLocation(e)))
5314+
forceExtractFunction(samMember, classId, extractBody = false, extractMethodAndParameterTypeAccesses = true, typeSub, classTypeArgs, overriddenAttributes = OverriddenFunctionAttributes(id = ids.function, sourceLoc = tw.getLocation(e), modality = Modality.FINAL))
53155315

53165316
addModifiers(ids.function, "override")
53175317
if (st.isSuspendFunctionOrKFunction()) {
@@ -5536,6 +5536,7 @@ open class KotlinFileExtractor(
55365536
val typeParameters: List<IrTypeParameter>? = null,
55375537
val isStatic: Boolean? = null,
55385538
val visibility: DescriptorVisibility? = null,
5539+
val modality: Modality? = null,
55395540
)
55405541

55415542
private fun peekDeclStackAsDeclarationParent(elementToReportOn: IrElement): IrDeclarationParent? {

0 commit comments

Comments
 (0)