JS: prevent optimizer from removing access to dynamic property access. See KT-15278
This commit is contained in:
@@ -1400,6 +1400,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertySideEffect.kt")
|
||||
public void testPropertySideEffect() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/dynamic/propertySideEffect.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("setByBrackets.kt")
|
||||
public void testSetByBrackets() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/dynamic/setByBrackets.kt");
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
@@ -137,8 +138,8 @@ public final class JsDescriptorUtils {
|
||||
}
|
||||
|
||||
public static boolean sideEffectsPossibleOnRead(@NotNull PropertyDescriptor property) {
|
||||
return !isDefaultAccessor(property.getGetter()) || ModalityKt.isOverridableOrOverrides(property) ||
|
||||
isStaticInitializationPossible(property);
|
||||
return DynamicCallsKt.isDynamic(property) || !isDefaultAccessor(property.getGetter()) ||
|
||||
ModalityKt.isOverridableOrOverrides(property) || isStaticInitializationPossible(property);
|
||||
}
|
||||
|
||||
private static boolean isStaticInitializationPossible(PropertyDescriptor property) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
var log = "";
|
||||
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "foo", {
|
||||
"get" : function () {
|
||||
log += "foo called";
|
||||
return "OK"
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
external class C
|
||||
|
||||
inline val C.foo: String
|
||||
get() = asDynamic().foo
|
||||
|
||||
external val log: String
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
c.foo
|
||||
if (log != "foo called") return "fail: $log"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user