Support val initialization in non-inline function with EXACTLY_ONCE effect
by generating a box for the value. #KT-26126 Fixed
This commit is contained in:
+18
@@ -3663,6 +3663,24 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/contracts")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Contracts extends AbstractIrJsCodegenBoxTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInContracts() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/contracts"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("exactlyOnceNotInline.kt")
|
||||
public void testExactlyOnceNotInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/contracts/exactlyOnceNotInline.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/controlStructures")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Generated
+10
@@ -64,6 +64,16 @@ public class IrJsInlineContractsTestsGenerated extends AbstractIrJsInlineContrac
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/definiteValInitialization.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("exactlyOnceCrossinline.kt")
|
||||
public void testExactlyOnceCrossinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/exactlyOnceCrossinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("exactlyOnceNoinline.kt")
|
||||
public void testExactlyOnceNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/exactlyOnceNoinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonLocalReturn.kt")
|
||||
public void testNonLocalReturn() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/nonLocalReturn.kt");
|
||||
|
||||
+18
@@ -3673,6 +3673,24 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/contracts")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Contracts extends AbstractJsCodegenBoxTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInContracts() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/contracts"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("exactlyOnceNotInline.kt")
|
||||
public void testExactlyOnceNotInline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/contracts/exactlyOnceNotInline.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/controlStructures")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Generated
+10
@@ -64,6 +64,16 @@ public class JsInlineContractsTestsGenerated extends AbstractJsInlineContractsTe
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/definiteValInitialization.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("exactlyOnceCrossinline.kt")
|
||||
public void testExactlyOnceCrossinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/exactlyOnceCrossinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("exactlyOnceNoinline.kt")
|
||||
public void testExactlyOnceNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/exactlyOnceNoinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonLocalReturn.kt")
|
||||
public void testNonLocalReturn() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/contracts/nonLocalReturn.kt");
|
||||
|
||||
+4
-15
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.expression;
|
||||
@@ -40,7 +29,7 @@ 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;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContextUtils.isBoxedLocalCapturedInClosure;
|
||||
|
||||
public class DestructuringDeclarationTranslator extends AbstractTranslator {
|
||||
|
||||
@@ -87,7 +76,7 @@ public class DestructuringDeclarationTranslator extends AbstractTranslator {
|
||||
entryInitializer = TranslationUtils.coerce(context(), entryInitializer, descriptor.getType());
|
||||
|
||||
JsName name = context().getNameForDescriptor(descriptor);
|
||||
if (isVarCapturedInClosure(context().bindingContext(), descriptor)) {
|
||||
if (isBoxedLocalCapturedInClosure(context().bindingContext(), descriptor)) {
|
||||
JsNameRef alias = getCapturedVarAccessor(name.makeRef());
|
||||
entryInitializer = JsAstUtils.wrapValue(alias, entryInitializer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user