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