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:
Ilmir Usmanov
2018-12-26 21:31:46 +03:00
parent a52f430d8f
commit 8a01da6ec6
20 changed files with 278 additions and 73 deletions
@@ -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)
@@ -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");
@@ -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)
@@ -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");
@@ -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);
}