diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt index 5cc1b6be3c7..1450e88866e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt @@ -152,7 +152,8 @@ interface SourceMapper { } fun createFromSmap(smap: SMAP): SourceMapper { - val sourceMapper = org.jetbrains.kotlin.codegen.inline2.DefaultSourceMapper(smap.sourceInfo) + val maxUsedIndex = smap.fileMappings.maxBy { it.lineMappings.maxBy { it.maxDest }!!.maxDest }!!.lineMappings.maxBy { it.maxDest }!!.maxDest + val sourceMapper = org.jetbrains.kotlin.codegen.inline2.DefaultSourceMapper(smap.sourceInfo, maxUsedIndex) smap.fileMappings.asSequence() //default one mapped through sourceInfo .filterNot { it == smap.default } @@ -337,6 +338,9 @@ data class RangeMapping(val source: Int, val dest: Int, var range: Int = 1) { var parent: FileMapping? = null private val skip = source == -1 && dest == -1 + val maxDest: Int + get() = dest + range - 1 + operator fun contains(destLine: Int): Boolean { return if (skip) true else dest <= destLine && destLine < dest + range } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt index 6eb6e19b79b..13c07457ecf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP2.kt @@ -81,8 +81,11 @@ open class InlineLambdaSourceMapper( } -open class DefaultSourceMapper(val sourceInfo: SourceInfo): SourceMapper { - protected var maxUsedValue: Int = sourceInfo.linesInFile +open class DefaultSourceMapper @JvmOverloads constructor( + val sourceInfo: SourceInfo, + protected var maxUsedValue: Int = sourceInfo.linesInFile +) : SourceMapper { + var lastVisited: RawFileMapping? = null private var lastMappedWithChanges: RawFileMapping? = null private var fileMappings: LinkedHashMap = linkedMapOf() @@ -92,7 +95,7 @@ open class DefaultSourceMapper(val sourceInfo: SourceInfo): SourceMapper { val name = sourceInfo.source val path = sourceInfo.pathOrCleanFQN origin = RawFileMapping(name, path) - origin.initRange(1, maxUsedValue) + origin.initRange(1, sourceInfo.linesInFile) fileMappings.put(createKey(name, path), origin) lastVisited = origin } diff --git a/compiler/tests-common/org/jetbrains/kotlin/codegen/SMAPTestUtil.kt b/compiler/tests-common/org/jetbrains/kotlin/codegen/SMAPTestUtil.kt index fcbf76277a3..572a10468bb 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/codegen/SMAPTestUtil.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/codegen/SMAPTestUtil.kt @@ -123,4 +123,4 @@ object SMAPTestUtil { } val RangeMapping.toRange: IntRange - get() = this.dest..this.dest + this.range - 1 + get() = this.dest..this.maxDest