diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/LabelNameRefreshingVisitor.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/LabelNameRefreshingVisitor.kt index 9a055b35a54..902047b7d40 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/LabelNameRefreshingVisitor.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/LabelNameRefreshingVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2017 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. @@ -27,7 +27,7 @@ class LabelNameRefreshingVisitor(val functionScope: JsFunctionScope) : JsVisitor override fun endVisit(x: JsBreak, ctx: JsContext) { val label = x.label?.name if (label != null) { - ctx.replaceMe(JsBreak(getSubstitution(label).makeRef())) + ctx.replaceMe(JsBreak(getSubstitution(label).makeRef()).source(x.source)) } super.endVisit(x, ctx) } @@ -35,7 +35,7 @@ class LabelNameRefreshingVisitor(val functionScope: JsFunctionScope) : JsVisitor override fun endVisit(x: JsContinue, ctx: JsContext) { val label = x.label?.name if (label != null) { - ctx.replaceMe(JsContinue(getSubstitution(label).makeRef())) + ctx.replaceMe(JsContinue(getSubstitution(label).makeRef()).source(x.source)) } super.endVisit(x, ctx) } diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/ReturnReplacingVisitor.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/ReturnReplacingVisitor.kt index 64e1064cef3..2e3c40cb5a8 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/ReturnReplacingVisitor.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/rewriters/ReturnReplacingVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 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. @@ -49,11 +49,11 @@ class ReturnReplacingVisitor( if (returnExpression != null && returnExpression.isTailCallSuspend) { returnReplacement.isSuspend = true } - ctx.addNext(JsExpressionStatement(returnReplacement)) + ctx.addNext(JsExpressionStatement(returnReplacement.apply { source = x.source })) } if (breakLabel != null) { - ctx.addNext(JsBreak(breakLabel)) + ctx.addNext(JsBreak(breakLabel).apply { source = x.source }) } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/JsLineNumberTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/JsLineNumberTestGenerated.java index 4729021d8bd..52757a22525 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/JsLineNumberTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/JsLineNumberTestGenerated.java @@ -54,6 +54,12 @@ public class JsLineNumberTestGenerated extends AbstractJsLineNumberTest { doTest(fileName); } + @TestMetadata("inlineReturn.kt") + public void testInlineReturn() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inlineReturn.kt"); + doTest(fileName); + } + @TestMetadata("inlining.kt") public void testInlining() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/lineNumbers/inlining.kt"); diff --git a/js/js.translator/testData/lineNumbers/inlineReturn.kt b/js/js.translator/testData/lineNumbers/inlineReturn.kt new file mode 100644 index 00000000000..6d5237cd05f --- /dev/null +++ b/js/js.translator/testData/lineNumbers/inlineReturn.kt @@ -0,0 +1,24 @@ +inline fun foo(x: Int): String { + if (x == 1) { + return "a" + + x + } + + print("!") + + if (x == 2) { + return "b" + + x + } + + println("#") + + return x.toString() +} + +fun bar(x: Int) { + println(foo(x + 1)) + println("%") +} + +// LINES: 2 3 4 7 9 10 11 14 16 * 20 * 2 3 3 7 9 10 10 14 16 20 21 \ No newline at end of file