From 1978bfcd85a0c1256d5edcfccfca7db7fdec1c78 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Thu, 24 Jun 2021 15:05:27 +0300 Subject: [PATCH] Rewrite rendering of meta info for CHECK_NOT_NULL in interpreter's test This way it is possible to unify rendering of elements built by psi2ir and fir2ir. --- compiler/testData/ir/interpreter/collections/mapOf.kt | 4 ++-- compiler/testData/ir/interpreter/jvm/classReference.kt | 4 ++-- .../test/backend/handlers/IrInterpreterBackendHandler.kt | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/compiler/testData/ir/interpreter/collections/mapOf.kt b/compiler/testData/ir/interpreter/collections/mapOf.kt index 6ba746d7418..0e592f9ddfc 100644 --- a/compiler/testData/ir/interpreter/collections/mapOf.kt +++ b/compiler/testData/ir/interpreter/collections/mapOf.kt @@ -9,8 +9,8 @@ const val contains2 = mapOf(1 to "1", 2 to "2", 3 to "3").c const val contains3 = mapOf(1 to "1", 2 to "2", 3 to "3").contains("1") const val contains4 = mapOf(1 to "1", 2 to "2", 3 to "3").containsValue("1") -const val get1 = mapOf(1 to "1", 2 to "2", 3 to "3").get(1)!! -const val get2 = mapOf(1 to "1", 2 to "2", 3 to "3")[2]!! +const val get1 = mapOf(1 to "1", 2 to "2", 3 to "3").get(1)!! +const val get2 = mapOf(1 to "1", 2 to "2", 3 to "3")[2]!! const val get3 = mapOf(1 to "1", 2 to "2", 3 to "3")[0].toString() const val keys = mapOf(1 to "1", 2 to "2", 3 to "3").keys.size diff --git a/compiler/testData/ir/interpreter/jvm/classReference.kt b/compiler/testData/ir/interpreter/jvm/classReference.kt index 7c32ae8ccc3..ec0cb27f29b 100644 --- a/compiler/testData/ir/interpreter/jvm/classReference.kt +++ b/compiler/testData/ir/interpreter/jvm/classReference.kt @@ -11,8 +11,8 @@ class A(val a: Int, val b: String) { fun Int.funWithExtension(other: Int) = this + other } -const val aSimpleName = A::class.simpleName!! -const val aQualifiedName = A::class.qualifiedName!! +const val aSimpleName = A::class.simpleName!! +const val aQualifiedName = A::class.qualifiedName!! //const val aMembers = A::class.members.joinToString() TODO -> `val test.A.a: kotlin.Int, val test.A.b: kotlin.String, val test.A.(kotlin.String.)propertyWithExtension: kotlin.Int, fun test.A.(kotlin.Int.)funWithExtension(kotlin.Int): kotlin.Int, fun test.A.equals(kotlin.Any?): kotlin.Boolean, fun test.A.hashCode(): kotlin.Int, fun test.A.toString(): kotlin.String` const val aConstructors = A::class.constructors.(kotlin.Int, kotlin.String): test.A`!>joinToString() const val aVisibility = A::class.visibility.toString() diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterBackendHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterBackendHandler.kt index ec0e4483a2b..86e09641b11 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterBackendHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrInterpreterBackendHandler.kt @@ -11,8 +11,8 @@ import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.interpreter.IrInterpreter -import org.jetbrains.kotlin.ir.interpreter.checker.IrCompileTimeChecker import org.jetbrains.kotlin.ir.util.copyTypeAndValueArgumentsFrom +import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.model.TestFile @@ -47,7 +47,12 @@ private class Evaluator(private val interpreter: IrInterpreter, private val glob is IrErrorExpression -> this.description else -> TODO("unsupported type ${this::class.java}") } - val metaInfo = IrInterpreterCodeMetaInfo(this.startOffset, this.endOffset, message, isError) + val startOffset = when { + // this additional check is needed to unify rendering from old and new frontends + original is IrCall && original.symbol.owner.fqNameWhenAvailable?.asString() == "kotlin.internal.ir.CHECK_NOT_NULL" -> endOffset - 2 + else -> startOffset + } + val metaInfo = IrInterpreterCodeMetaInfo(startOffset, this.endOffset, message, isError) globalMetadataInfoHandler.addMetadataInfosForFile(testFile, listOf(metaInfo)) return if (this !is IrErrorExpression) this else original }