diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java index bc1eb0dfb0a..bcaad80282f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -370,7 +370,7 @@ public class InlineCodegen extends CallGenerator { MethodInliner inliner = new MethodInliner( node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule, "Method inlining " + callElement.getText(), - createNestedSourceMapper(nodeAndSmap), info.getCallSiteInfo(), + createNestedSourceMapper(nodeAndSmap, sourceMapper), info.getCallSiteInfo(), AnnotationUtilKt.hasInlineOnlyAnnotation(functionDescriptor) ? new InlineOnlySmapSkipper(codegen) : null ); //with captured @@ -882,8 +882,8 @@ public class InlineCodegen extends CallGenerator { } } - private SourceMapper createNestedSourceMapper(@NotNull SMAPAndMethodNode nodeAndSmap) { - return new NestedSourceMapper(sourceMapper, nodeAndSmap.getRanges(), nodeAndSmap.getClassSMAP().getSourceInfo()); + public static SourceMapper createNestedSourceMapper(@NotNull SMAPAndMethodNode nodeAndSmap, @NotNull SourceMapper parent) { + return new NestedSourceMapper(parent, nodeAndSmap.getRanges(), nodeAndSmap.getClassSMAP().getSourceInfo()); } static void reportIncrementalInfo( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt index ea005197ab6..0d2430dbceb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenForDefaultBody.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.inline.InlineUtil import org.jetbrains.org.objectweb.asm.Type +import org.jetbrains.org.objectweb.asm.tree.MethodNode class InlineCodegenForDefaultBody( function: FunctionDescriptor, @@ -34,6 +35,8 @@ class InlineCodegenForDefaultBody( val state: GenerationState ) : CallGenerator() { + private val sourceMapper: SourceMapper = codegen.parentCodegen.orCreateSourceMapper + private val functionDescriptor = if (InlineUtil.isArrayConstructorWithLambda(function)) FictitiousArrayConstructor.create(function as ConstructorDescriptor) @@ -57,7 +60,19 @@ class InlineCodegenForDefaultBody( override fun genCallInner(callableMethod: Callable, resolvedCall: ResolvedCall<*>?, callDefault: Boolean, codegen: ExpressionCodegen) { val nodeAndSmap = InlineCodegen.createMethodNode(functionDescriptor, jvmSignature, codegen, context, callDefault, state) - nodeAndSmap.node.accept(MethodBodyVisitor(codegen.v)) + val childSourceMapper = InlineCodegen.createNestedSourceMapper(nodeAndSmap, sourceMapper) + + val node = nodeAndSmap.node + val transformedMethod = MethodNode( + node.access, + node.name, + node.desc, + node.signature, + node.exceptions.toTypedArray()) + + node.accept(InlineAdapter(transformedMethod, 0, childSourceMapper)) + + transformedMethod.accept(MethodBodyVisitor(codegen.v)) } override fun afterParameterPut(type: Type, stackValue: StackValue?, parameterIndex: Int) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPAndMethodNode.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPAndMethodNode.kt index cb0183e2f72..3733da67d0e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPAndMethodNode.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAPAndMethodNode.kt @@ -29,15 +29,15 @@ class SMAPAndMethodNode(val node: MethodNode, val classSMAP: SMAP) { } private fun createLineNumberSequence(node: MethodNode, classSMAP: SMAP): Sequence { - return InsnSequence(node.instructions.first, null).filterIsInstance().map { node -> - val index = classSMAP.intervals.binarySearch(RangeMapping(node.line, node.line, 1), Comparator { + return InsnSequence(node.instructions.first, null).filterIsInstance().map { lineNumber -> + val index = classSMAP.intervals.binarySearch(RangeMapping(lineNumber.line, lineNumber.line, 1), Comparator { value, key -> if (key.dest in value) 0 else RangeMapping.Comparator.compare(value, key) }) if (index < 0) { - error("Unmapped label in inlined function $node ${node.line}") + error("Unmapped label in inlined function $node ${lineNumber.line}") } - LabelAndMapping(node, classSMAP.intervals[index]) + LabelAndMapping(lineNumber, classSMAP.intervals[index]) } } diff --git a/compiler/testData/codegen/boxInline/defaultValues/kt11479.kt b/compiler/testData/codegen/boxInline/defaultValues/kt11479.kt new file mode 100644 index 00000000000..9c757fcfdab --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/kt11479.kt @@ -0,0 +1,25 @@ +// FILE: 1.kt +package test + +inline fun log(lazyMessage: () -> Any?) { + lazyMessage() +} + +// FILE: 2.kt + +import test.* + +inline fun getOrCreate( + z : Boolean = false, + s: () -> String +) { + log { s() } +} + + +fun box(): String { + var z = "fail" + getOrCreate { z = "OK"; z } + + return z +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/kt11479InlinedDefaultParameter.kt b/compiler/testData/codegen/boxInline/defaultValues/kt11479InlinedDefaultParameter.kt new file mode 100644 index 00000000000..65308a1fd16 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/kt11479InlinedDefaultParameter.kt @@ -0,0 +1,30 @@ +// FILE: 1.kt +package test + +inline fun log(lazyMessage: () -> Any?) { + lazyMessage() +} + +inline fun z(): Boolean { + "zzz" + return true +} + +// FILE: 2.kt + +import test.* + +inline fun getOrCreate( + z : Boolean = z(), + s: () -> String +) { + log { s() } +} + + +fun box(): String { + var z = "fail" + getOrCreate { z = "OK"; z } + + return z +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/smap/assertion.kt b/compiler/testData/codegen/boxInline/smap/assertion.kt index a9b1191f366..88804418769 100644 --- a/compiler/testData/codegen/boxInline/smap/assertion.kt +++ b/compiler/testData/codegen/boxInline/smap/assertion.kt @@ -37,6 +37,17 @@ fun box(): String { // FILE: 1.smap +SMAP +1.kt +Kotlin +*S Kotlin +*F ++ 1 1.kt +test/_1Kt +*L +1#1,25:1 +*E + // FILE: 2.smap SMAP diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 5b184fb6b40..672e80e67b5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -709,6 +709,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("kt11479.kt") + public void testKt11479() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479.kt"); + doTest(fileName); + } + + @TestMetadata("kt11479InlinedDefaultParameter.kt") + public void testKt11479InlinedDefaultParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479InlinedDefaultParameter.kt"); + doTest(fileName); + } + @TestMetadata("kt5685.kt") public void testKt5685() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 440e54c6ca5..616d986275c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -709,6 +709,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("kt11479.kt") + public void testKt11479() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479.kt"); + doTest(fileName); + } + + @TestMetadata("kt11479InlinedDefaultParameter.kt") + public void testKt11479InlinedDefaultParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479InlinedDefaultParameter.kt"); + doTest(fileName); + } + @TestMetadata("kt5685.kt") public void testKt5685() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt");