Skip to content

Commit a8a8e06

Browse files
committed
[JS] Fix getting names of local delegated properties
The test would fail with "Fail 2: property2" because invoking the property2 delegate triggered a side effect due to a global function being mutated. Namely, in `getLocalDelegateReference` a contextless lambda was created and later passed to `getPropertyCallableRef`, which mutated it. However, because the lambda was contextless, it was transformed into a global function, so the global function was mutated instead, which caused unexpected side effects. ^KT-78073 Fixed (cherry picked from commit fe7dda9)
1 parent 3b804bc commit a8a8e06

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compiler/testData/codegen/box/delegatedProperty/local/kt78073.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
2-
// ^ KT-78073
1+
// ISSUE: KT-78073
32

43
import kotlin.reflect.KProperty
54

libraries/stdlib/js/runtime/reflectRuntime.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ internal fun getPropertyCallableRef(
2424
).unsafeCast<KProperty<*>>()
2525
}
2626

27+
@Suppress("unused") // usages are generated by the compiler
2728
internal fun getLocalDelegateReference(name: String, superType: dynamic, mutable: Boolean): KProperty<*> {
28-
val lambda = { throw UnsupportedOperationException("Not supported for local property reference.") }
29+
// getPropertyCallableRef will mutate the lambda, so it's important that the lambda is not transformed into a global function.
30+
val lambda = @JsNoLifting { throwUnsupportedOperationException("Not supported for local property reference.") }
2931
return getPropertyCallableRef(name, 0, superType, lambda, if (mutable) lambda else null)
3032
}
3133

0 commit comments

Comments
 (0)