From a840cf76433ad30c9f3fe83d7b9b9f61e4019d8f Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 13 Apr 2017 10:04:36 +0300 Subject: [PATCH] Fix source range tests: support "undefined" offsets --- .../org/jetbrains/kotlin/psi2ir/PsiSourceManager.kt | 2 ++ .../augmentedAssignmentWithExpression.txt | 13 +++++++++++-- compiler/testData/ir/sourceRanges/kt17108.txt | 12 ++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/PsiSourceManager.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/PsiSourceManager.kt index a5f0d854f53..dab589da032 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/PsiSourceManager.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/PsiSourceManager.kt @@ -41,11 +41,13 @@ class PsiSourceManager : SourceManager { } override fun getLineNumber(offset: Int): Int { + if (offset < 0) return -1 val index = lineStartOffsets.binarySearch(offset) return if (index >= 0) index else -index - 2 } override fun getColumnNumber(offset: Int): Int { + if (offset < 0) return -1 val lineNumber = getLineNumber(offset) return offset - lineStartOffsets[lineNumber] } diff --git a/compiler/testData/ir/sourceRanges/augmentedAssignmentWithExpression.txt b/compiler/testData/ir/sourceRanges/augmentedAssignmentWithExpression.txt index 738ae815b3f..842b50bfc3c 100644 --- a/compiler/testData/ir/sourceRanges/augmentedAssignmentWithExpression.txt +++ b/compiler/testData/ir/sourceRanges/augmentedAssignmentWithExpression.txt @@ -1,24 +1,32 @@ @0:0..23:0 FILE /augmentedAssignmentWithExpression.kt @2:0..8:1 CLASS CLASS Host + @2:0..8:1 VALUE_PARAMETER @2:0..8:1 CONSTRUCTOR public constructor Host() @2:0..8:1 BLOCK_BODY @2:0..8:1 DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @2:0..8:1 INSTANCE_INITIALIZER_CALL classDescriptor='Host' @3:4..38 FUN public final operator fun plusAssign(x: kotlin.Int): kotlin.Unit + @3:4..38 VALUE_PARAMETER + @3:28..34 VALUE_PARAMETER value-parameter x: kotlin.Int @3:36..38 BLOCK_BODY @5:4..7:5 FUN public final fun test1(): kotlin.Unit + @5:4..7:5 VALUE_PARAMETER @5:16..7:5 BLOCK_BODY @6:8..17 CALL 'plusAssign(Int): Unit' type=kotlin.Unit origin=PLUSEQ - @6:8..12 GET_VAR '' type=test.Host origin=null + @6:8..12 GET_VAR '' type=test.Host origin=PLUSEQ @6:16..17 CONST Int type=kotlin.Int value='1' + @-1:-1..-1 FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + @-1:-1..-1 FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + @-1:-1..-1 FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String @10:0..18 FUN public fun foo(): test.Host @10:12..18 BLOCK_BODY @10:12..18 RETURN type=kotlin.Nothing from='foo(): Host' @10:12..18 CALL 'constructor Host()' type=test.Host origin=null @12:0..14:1 FUN public fun test.Host.test2(): kotlin.Unit + @12:4..8 VALUE_PARAMETER @12:17..14:1 BLOCK_BODY @13:4..13 CALL 'plusAssign(Int): Unit' type=kotlin.Unit origin=PLUSEQ - @13:4..8 GET_VAR '' type=test.Host origin=null + @13:4..8 GET_VAR '' type=test.Host origin=PLUSEQ @13:12..13 CONST Int type=kotlin.Int value='1' @16:0..18:1 FUN public fun test3(): kotlin.Unit @16:12..18:1 BLOCK_BODY @@ -26,6 +34,7 @@ @17:4..9 CALL 'foo(): Host' type=test.Host origin=null @17:13..14 CONST Int type=kotlin.Int value='1' @20:0..22:1 FUN public fun test4(a: () -> test.Host): kotlin.Unit + @20:10..23 VALUE_PARAMETER value-parameter a: () -> test.Host @20:25..22:1 BLOCK_BODY @21:4..12 CALL 'plusAssign(Int): Unit' type=kotlin.Unit origin=PLUSEQ @21:4..7 CALL 'invoke(): Host' type=test.Host origin=INVOKE diff --git a/compiler/testData/ir/sourceRanges/kt17108.txt b/compiler/testData/ir/sourceRanges/kt17108.txt index c2bf1bc950b..59dcd2c99fd 100644 --- a/compiler/testData/ir/sourceRanges/kt17108.txt +++ b/compiler/testData/ir/sourceRanges/kt17108.txt @@ -1,7 +1,19 @@ @0:0..26:1 FILE /kt17108.kt @0:0..26:1 CLASS INTERFACE Boolean @5:4..8:38 FUN public abstract operator fun not(): Boolean + @5:4..8:38 VALUE_PARAMETER @10:4..13:42 FUN public abstract infix fun and(other: Boolean): Boolean + @10:4..13:42 VALUE_PARAMETER + @13:18..32 VALUE_PARAMETER value-parameter other: Boolean @15:4..18:41 FUN public abstract infix fun or(other: Boolean): Boolean + @15:4..18:41 VALUE_PARAMETER + @18:17..31 VALUE_PARAMETER value-parameter other: Boolean @20:4..23:42 FUN public abstract infix fun xor(other: Boolean): Boolean + @20:4..23:42 VALUE_PARAMETER + @23:18..32 VALUE_PARAMETER value-parameter other: Boolean @25:4..38 FUN public abstract fun compareTo(other: Boolean): kotlin.Int + @25:4..38 VALUE_PARAMETER + @25:18..32 VALUE_PARAMETER value-parameter other: Boolean + @-1:-1..-1 FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + @-1:-1..-1 FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + @-1:-1..-1 FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String