From dd062bfd6dd93764990881f4c18d83e7c2ecbbad Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 13 Sep 2016 17:28:46 +0300 Subject: [PATCH] JS: add explanation to inline/arrayLiteralAliasing.kt test --- .../inline/cases/arrayLiteralAliasing.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/js/js.translator/testData/inline/cases/arrayLiteralAliasing.kt b/js/js.translator/testData/inline/cases/arrayLiteralAliasing.kt index f2b2d232001..e657cb17e0f 100644 --- a/js/js.translator/testData/inline/cases/arrayLiteralAliasing.kt +++ b/js/js.translator/testData/inline/cases/arrayLiteralAliasing.kt @@ -1,3 +1,29 @@ +/* +This tests that variables (aliases) are created for array literals. + +Let's say we have the following JS code: + +function f(a) { + a.push(0); + return a; +} + +// ... +console.log(f([])); +In this case copying f's argument a without creating a variable is incorrect because it would produce the following code: + +[].push(0); +console.log([]); +This is the correct version: + +var a = []; +a.push(0); +console.log(a); +The test was created because we don't want to create aliases for literals. +However in our class hierarchy JsArrayLiteral is subclass of JsLiteral, +which makes very easy to implement incorrect aliasing logic. + */ + package foo // CHECK_NOT_CALLED: moveTo