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.
This commit is contained in:
Ivan Kylchik
2021-06-24 15:05:27 +03:00
committed by TeamCityServer
parent a9abf3b9b6
commit 1978bfcd85
3 changed files with 11 additions and 6 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ const val contains2 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>c
const val contains3 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `false`!>contains<Any, String>("1")<!>
const val contains4 = mapOf(1 to "1", 2 to "2", 3 to "3").<!EVALUATED: `true`!>containsValue("1")<!>
const val get1 = <!EVALUATED: `1`!>mapOf(1 to "1", 2 to "2", 3 to "3").get(1)!!<!>
const val get2 = <!EVALUATED: `2`!>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)<!EVALUATED: `1`!>!!<!>
const val get2 = mapOf(1 to "1", 2 to "2", 3 to "3")[2]<!EVALUATED: `2`!>!!<!>
const val get3 = mapOf(1 to "1", 2 to "2", 3 to "3")[0].<!EVALUATED: `null`!>toString()<!>
const val keys = mapOf(1 to "1", 2 to "2", 3 to "3").keys.<!EVALUATED: `3`!>size<!>
+2 -2
View File
@@ -11,8 +11,8 @@ class A(val a: Int, val b: String) {
fun Int.funWithExtension(other: Int) = this + other
}
const val aSimpleName = <!EVALUATED: `A`!>A::class.simpleName!!<!>
const val aQualifiedName = <!EVALUATED: `test.A`!>A::class.qualifiedName!!<!>
const val aSimpleName = A::class.simpleName<!EVALUATED: `A`!>!!<!>
const val aQualifiedName = A::class.qualifiedName<!EVALUATED: `test.A`!>!!<!>
//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.<!EVALUATED: `fun <init>(kotlin.Int, kotlin.String): test.A`!>joinToString()<!>
const val aVisibility = A::class.visibility.<!EVALUATED: `PUBLIC`!>toString()<!>
@@ -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
}