JS: add explanation to inline/arrayLiteralAliasing.kt test
This commit is contained in:
@@ -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
|
package foo
|
||||||
|
|
||||||
// CHECK_NOT_CALLED: moveTo
|
// CHECK_NOT_CALLED: moveTo
|
||||||
|
|||||||
Reference in New Issue
Block a user