Skip to content

Commit 4bf855d

Browse files
committed
[K/JS] Fix incremental compilation for overridden external properties
There was an issue with a non-external class overriding an external property with the incremental compilation. ```kotlin external interface Foo { val a: Int } class FooImpl(override val a: Int): Foo ``` In the case when such a module is not marked as dirty (so it will be not re-compiled), the lowering was failing with an internal compiler exception. The body of the ` FooImpl ` constructor was not loaded during the re-compilation. ^KT-79050 Fixed Merge-request: KT-MR-22573 Merged-by: Artem Kobzar <[email protected]>
1 parent 69050bd commit 4bf855d

16 files changed

+101
-9
lines changed

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExternalPropertyOverridingLowering.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,18 @@ class ExternalPropertyOverridingLowering(private val context: JsIrBackendContext
9191

9292
if (overriddenExternalPropertyAccessors.isEmpty()) return null
9393

94-
val externalPropertyAccessorsTransformer =
95-
ExternalPropertySuperAccessTransformer(context, declaration, overriddenExternalPropertyAccessors)
94+
val classPrimaryConstructor = declaration.primaryConstructor
95+
?: declaration.syntheticPrimaryConstructor
96+
?: compilationException("Unexpected primary constructor for processing irClass", declaration)
97+
98+
if (classPrimaryConstructor.body == null) return null
99+
100+
val externalPropertyAccessorsTransformer = ExternalPropertySuperAccessTransformer(
101+
context,
102+
declaration,
103+
classPrimaryConstructor,
104+
overriddenExternalPropertyAccessors
105+
)
96106

97107
declaration.transformChildren(externalPropertyAccessorsTransformer, null)
98108

@@ -135,16 +145,13 @@ class ExternalPropertyOverridingLowering(private val context: JsIrBackendContext
135145
private class ExternalPropertySuperAccessTransformer(
136146
private val context: JsIrBackendContext,
137147
private val irClass: IrClass,
148+
private val primaryConstructor: IrConstructor,
138149
private val overriddenExternalPropertiesAccessor: Set<IrSimpleFunctionSymbol>,
139150
) : IrTransformer<IrFunction?>() {
140151
val superAccessMap = mutableMapOf<IrProperty, ExternalPropertySuperAccess>()
141152

142-
val parentClassPrimaryConstructor = irClass.primaryConstructor
143-
?: irClass.syntheticPrimaryConstructor
144-
?: compilationException("Unexpected primary constructor for processing irClass", irClass)
145-
146-
val primaryConstructorBody = parentClassPrimaryConstructor.body as? IrBlockBody
147-
?: compilationException("Unexpected body of primary constructor for processing irClass", parentClassPrimaryConstructor)
153+
val primaryConstructorBody = primaryConstructor.body as? IrBlockBody
154+
?: compilationException("Unexpected body of primary constructor for processing irClass", primaryConstructor)
148155

149156
val parentClassDispatchReceiver = irClass.thisReceiver ?: compilationException("Unexpected thisReceiver of class", irClass)
150157

@@ -197,7 +204,7 @@ class ExternalPropertyOverridingLowering(private val context: JsIrBackendContext
197204
private fun IrCall.createVariableWithExternalPropertyValue() =
198205
JsIrBuilder.buildVar(
199206
type = type,
200-
parent = parentClassPrimaryConstructor,
207+
parent = primaryConstructor,
201208
origin = EXTERNAL_SUPER_ACCESSORS_ORIGIN,
202209
initializer = symbol.createExternalSuperFieldAccess()
203210
)

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsFirES6InvalidationPerFileTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsFirES6InvalidationPerModuleTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsFirInvalidationPerFileTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsFirInvalidationPerModuleTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsIrES6InvalidationPerFileTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsIrES6InvalidationPerModuleTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsIrInvalidationPerFileTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/incremental/JsIrInvalidationPerModuleTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TARGET_BACKEND: JS_IR, JS_IR_ES6

0 commit comments

Comments
 (0)