Fix capturing variables declared via destructuring (#KT-14535 fixed).
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
// TODO: enable JS backend when issue KT-14535 is fixed
|
||||
// IGNORE_BACKEND: JS
|
||||
class A {
|
||||
operator fun component1() = 1
|
||||
operator fun component2() = 2
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// TODO: enable JS backend when issue KT-14535 is fixed
|
||||
// IGNORE_BACKEND: JS
|
||||
class A {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// TODO: enable JS backend when issue KT-14535 is fixed
|
||||
// IGNORE_BACKEND: JS
|
||||
class A {
|
||||
operator fun component1() = 1
|
||||
operator fun component2() = 2
|
||||
|
||||
+18
-18
@@ -31,24 +31,6 @@ import java.util.regex.Pattern;
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class MultiDeclarationTestsGenerated extends AbstractMultiDeclarationTests {
|
||||
@TestMetadata("VarCapturedInFunctionLiteral.kt")
|
||||
public void ignoredVarCapturedInFunctionLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/VarCapturedInFunctionLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarCapturedInLocalFunction.kt")
|
||||
public void ignoredVarCapturedInLocalFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/VarCapturedInLocalFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarCapturedInObjectLiteral.kt")
|
||||
public void ignoredVarCapturedInObjectLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/VarCapturedInObjectLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInMultiDecl() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/multiDecl"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
@@ -119,6 +101,24 @@ public class MultiDeclarationTestsGenerated extends AbstractMultiDeclarationTest
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarCapturedInFunctionLiteral.kt")
|
||||
public void testVarCapturedInFunctionLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/VarCapturedInFunctionLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarCapturedInLocalFunction.kt")
|
||||
public void testVarCapturedInLocalFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/VarCapturedInLocalFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VarCapturedInObjectLiteral.kt")
|
||||
public void testVarCapturedInObjectLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/VarCapturedInObjectLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/multiDecl/forIterator")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+8
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.reference.CallExpressionTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
@@ -37,7 +38,9 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.context.Namer.getCapturedVarAccessor;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.InlineUtils.setInlineCallMetadata;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContextUtils.isVarCapturedInClosure;
|
||||
|
||||
public class DestructuringDeclarationTranslator extends AbstractTranslator {
|
||||
|
||||
@@ -92,6 +95,11 @@ public class DestructuringDeclarationTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
JsName name = context().getNameForDescriptor(descriptor);
|
||||
if (isVarCapturedInClosure(context().bindingContext(), descriptor)) {
|
||||
JsNameRef alias = getCapturedVarAccessor(name.makeRef());
|
||||
entryInitializer = JsAstUtils.wrapValue(alias, entryInitializer);
|
||||
}
|
||||
|
||||
jsVars.add(new JsVars.JsVar(name, entryInitializer));
|
||||
}
|
||||
return new JsVars(jsVars, true);
|
||||
|
||||
Reference in New Issue
Block a user