Skip to content

Commit cddb5c5

Browse files
authored
Merge pull request github#11616 from smowton/smowton/fix/callable-modality-abstraction
Kotlin: extract callable modality
2 parents 2db77a7 + 1d209d1 commit cddb5c5

File tree

5 files changed

+139
-110
lines changed

5 files changed

+139
-110
lines changed

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

Lines changed: 10 additions & 2 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)
@@ -1243,6 +1243,13 @@ open class KotlinFileExtractor(
12431243
if (f.isSuspend) {
12441244
addModifiers(id, "suspend")
12451245
}
1246+
if (f.symbol !is IrConstructorSymbol) {
1247+
when(overriddenAttributes?.modality ?: (f as? IrSimpleFunction)?.modality) {
1248+
Modality.ABSTRACT -> addModifiers(id, "abstract")
1249+
Modality.FINAL -> addModifiers(id, "final")
1250+
else -> Unit
1251+
}
1252+
}
12461253

12471254
linesOfCode?.linesOfCodeInDeclaration(f, id)
12481255

@@ -5304,7 +5311,7 @@ open class KotlinFileExtractor(
53045311
// we would need to compose generic type substitutions -- for example, if we're implementing
53055312
// T UnaryOperator<T>.apply(T t) here, we would need to compose substitutions so we can implement
53065313
// the real underlying R Function<T, R>.apply(T t).
5307-
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))
53085315

53095316
addModifiers(ids.function, "override")
53105317
if (st.isSuspendFunctionOrKFunction()) {
@@ -5529,6 +5536,7 @@ open class KotlinFileExtractor(
55295536
val typeParameters: List<IrTypeParameter>? = null,
55305537
val isStatic: Boolean? = null,
55315538
val visibility: DescriptorVisibility? = null,
5539+
val modality: Modality? = null,
55325540
)
55335541

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

0 commit comments

Comments
 (0)