From cf425ffded03c26b45a9ea59aa606a74bc71c2c2 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 12 Feb 2024 12:43:49 +0100 Subject: [PATCH] Tests: fix stdlib declarations in IR interpreter test data Fix some unresolved supertypes. This is necessary to be able to enable IR fake override builder by default (KT-61514), because it traverses all supertypes and asserts that they're classes, so that it can build fake overrides for declarations from there. Without this change, for example `IrFakeOverrideBuilder.buildFakeOverridesForClass` would crash. --- .../exceptions/classCastException.kt | 4 +- .../ir/interpreter/helpers/Collections.kt | 2 +- .../testData/ir/interpreter/helpers/Maps.kt | 2 +- .../testData/ir/interpreter/helpers/Regex.kt | 64 +++++++++++++++++++ .../ir/interpreter/helpers/Sequences.kt | 7 +- .../testData/ir/interpreter/helpers/Sets.kt | 2 +- .../ir/interpreter/helpers/Standard.kt | 4 ++ .../helpers/StringNumberConversionsJVM.kt | 4 ++ .../interpreter/helpers/utils/kotlinUtils.kt | 4 +- ...IrInterpreterHelpersSourceFilesProvider.kt | 1 - 10 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 compiler/testData/ir/interpreter/helpers/Regex.kt create mode 100644 compiler/testData/ir/interpreter/helpers/StringNumberConversionsJVM.kt diff --git a/compiler/testData/ir/interpreter/exceptions/classCastException.kt b/compiler/testData/ir/interpreter/exceptions/classCastException.kt index 13f175f49af..9c18cee3f55 100644 --- a/compiler/testData/ir/interpreter/exceptions/classCastException.kt +++ b/compiler/testData/ir/interpreter/exceptions/classCastException.kt @@ -58,7 +58,7 @@ const val stringList = (classCastException.kt:54) at ClassCastExceptionKt.stringList.Function$0.invoke(classCastException.kt:0) - at StandardKt.kotlin.let(Standard.kt:32) + at StandardKt.kotlin.let(Standard.kt:36) at ClassCastExceptionKt.(classCastException.kt:53)`!>getIntList>().let { it[0].length } @@ -66,7 +66,7 @@ const val nullableStringList = (classCastException.kt) at ClassCastExceptionKt.nullableStringList.Function$0.invoke(classCastException.kt:0) - at StandardKt.kotlin.let(Standard.kt:32) + at StandardKt.kotlin.let(Standard.kt:36) at ClassCastExceptionKt.(classCastException.kt:56)`!>getStringNullableList>().let { it[0].length } const val nullableStringLength = { override fun previous(): Nothing = throw NoSuchElementException() } -internal object EmptyList : List, Serializable, RandomAccess { +internal object EmptyList : List, java.io.Serializable, RandomAccess { private const val serialVersionUID: Long = -7390468764508069838L override fun equals(other: Any?): Boolean = other is List<*> && other.isEmpty() diff --git a/compiler/testData/ir/interpreter/helpers/Maps.kt b/compiler/testData/ir/interpreter/helpers/Maps.kt index 6e74ca8a658..c79f5a68721 100644 --- a/compiler/testData/ir/interpreter/helpers/Maps.kt +++ b/compiler/testData/ir/interpreter/helpers/Maps.kt @@ -5,7 +5,7 @@ package kotlin.collections import kotlin.sequences.* -private object EmptyMap : Map, Serializable { +private object EmptyMap : Map, java.io.Serializable { private const val serialVersionUID: Long = 8246714829545688274 override fun equals(other: Any?): Boolean = other is Map<*, *> && other.isEmpty() diff --git a/compiler/testData/ir/interpreter/helpers/Regex.kt b/compiler/testData/ir/interpreter/helpers/Regex.kt new file mode 100644 index 00000000000..5dbd69f63fe --- /dev/null +++ b/compiler/testData/ir/interpreter/helpers/Regex.kt @@ -0,0 +1,64 @@ +package kotlin.text + +public class Regex { + public constructor(pattern: String) = TODO() + + public constructor(pattern: String, option: RegexOption) = TODO() + + public constructor(pattern: String, options: Set) = TODO() + + public val pattern: String + get() = TODO() + + public val options: Set + get() = TODO() + + public fun matchEntire(input: CharSequence): MatchResult? = TODO() + + public infix fun matches(input: CharSequence): Boolean = TODO() + + @SinceKotlin("1.7") + @WasExperimental(ExperimentalStdlibApi::class) + public fun matchAt(input: CharSequence, index: Int): MatchResult? = TODO() + + @SinceKotlin("1.7") + @WasExperimental(ExperimentalStdlibApi::class) + public fun matchesAt(input: CharSequence, index: Int): Boolean = TODO() + + public fun containsMatchIn(input: CharSequence): Boolean = TODO() + + public fun replace(input: CharSequence, replacement: String): String = TODO() + + public fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String = TODO() + + public fun replaceFirst(input: CharSequence, replacement: String): String = TODO() + + public fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = TODO() + + public fun findAll(input: CharSequence, startIndex: Int = 0): Sequence = TODO() + + public fun split(input: CharSequence, limit: Int = 0): List = TODO() + + @SinceKotlin("1.6") + @WasExperimental(ExperimentalStdlibApi::class) + public fun splitToSequence(input: CharSequence, limit: Int = 0): Sequence = TODO() + + public companion object { + public fun fromLiteral(literal: String): Regex = TODO() + + public fun escape(literal: String): String = TODO() + + public fun escapeReplacement(literal: String): String = TODO() + } +} + +public class MatchGroup { + public val value: String + get() = TODO() +} + +public enum class RegexOption { + IGNORE_CASE, + + MULTILINE +} diff --git a/compiler/testData/ir/interpreter/helpers/Sequences.kt b/compiler/testData/ir/interpreter/helpers/Sequences.kt index dd06694ad72..e221a6785ca 100644 --- a/compiler/testData/ir/interpreter/helpers/Sequences.kt +++ b/compiler/testData/ir/interpreter/helpers/Sequences.kt @@ -19,6 +19,11 @@ private object EmptySequence : Sequence, DropTakeSequence { override fun take(n: Int) = EmptySequence } +internal interface DropTakeSequence : Sequence { + fun drop(n: Int): Sequence + fun take(n: Int): Sequence +} + public inline fun Sequence?.orEmpty(): Sequence = this ?: emptySequence() private class GeneratorSequence(private val getInitialValue: () -> T?, private val getNextValue: (T) -> T?) : Sequence { @@ -119,4 +124,4 @@ private fun Appendable.appendElement(element: T, transform: ((T) -> CharSequ element is Char -> append(element) else -> append(element.toString()) } -} \ No newline at end of file +} diff --git a/compiler/testData/ir/interpreter/helpers/Sets.kt b/compiler/testData/ir/interpreter/helpers/Sets.kt index cf98fc04d97..7e2fd15371b 100644 --- a/compiler/testData/ir/interpreter/helpers/Sets.kt +++ b/compiler/testData/ir/interpreter/helpers/Sets.kt @@ -3,7 +3,7 @@ package kotlin.collections -internal object EmptySet : Set, Serializable { +internal object EmptySet : Set, java.io.Serializable { private const val serialVersionUID: Long = 3406603774387020532 override fun equals(other: Any?): Boolean = other is Set<*> && other.isEmpty() diff --git a/compiler/testData/ir/interpreter/helpers/Standard.kt b/compiler/testData/ir/interpreter/helpers/Standard.kt index b6848f099b1..cb87db954b5 100644 --- a/compiler/testData/ir/interpreter/helpers/Standard.kt +++ b/compiler/testData/ir/interpreter/helpers/Standard.kt @@ -2,6 +2,10 @@ package kotlin import kotlin.* +public class NotImplementedError(message: String = "An operation is not implemented.") : Error(message) + +public inline fun TODO(): Nothing = throw NotImplementedError() + public inline fun run(block: () -> R): R { return block() } diff --git a/compiler/testData/ir/interpreter/helpers/StringNumberConversionsJVM.kt b/compiler/testData/ir/interpreter/helpers/StringNumberConversionsJVM.kt new file mode 100644 index 00000000000..24330526333 --- /dev/null +++ b/compiler/testData/ir/interpreter/helpers/StringNumberConversionsJVM.kt @@ -0,0 +1,4 @@ +package kotlin.text + +@SinceKotlin("1.2") +public actual inline fun Long.toString(radix: Int): String = TODO() diff --git a/compiler/testData/ir/interpreter/helpers/utils/kotlinUtils.kt b/compiler/testData/ir/interpreter/helpers/utils/kotlinUtils.kt index 2de9c66bfc0..d611f411985 100644 --- a/compiler/testData/ir/interpreter/helpers/utils/kotlinUtils.kt +++ b/compiler/testData/ir/interpreter/helpers/utils/kotlinUtils.kt @@ -5,7 +5,7 @@ public inline val Char.code: Int get() = this.toInt() expect fun Double.isNaN(): Boolean expect fun Float.isNaN(): Boolean -public data class Pair(public val first: A, public val second: B) : Serializable { +public data class Pair(public val first: A, public val second: B) : java.io.Serializable { public override fun toString(): String = "($first, $second)" } @@ -15,7 +15,7 @@ public fun Pair.toList(): List = listOf(first, second) public data class Triple( public val first: A, public val second: B, public val third: C -) : Serializable { +) : java.io.Serializable { public override fun toString(): String = "($first, $second, $third)" } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/sourceProviders/IrInterpreterHelpersSourceFilesProvider.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/sourceProviders/IrInterpreterHelpersSourceFilesProvider.kt index e869a8897f2..07d0a273195 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/sourceProviders/IrInterpreterHelpersSourceFilesProvider.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/sourceProviders/IrInterpreterHelpersSourceFilesProvider.kt @@ -28,7 +28,6 @@ class IrInterpreterHelpersSourceFilesProvider(testServices: TestServices) : Addi "./libraries/stdlib/jvm/runtime/kotlin/TypeAliases.kt", "./libraries/stdlib/jvm/runtime/kotlin/text/TypeAliases.kt", "./libraries/stdlib/jvm/src/kotlin/collections/TypeAliases.kt", - "./libraries/stdlib/common/src/kotlin/TextH.kt", "./libraries/stdlib/src/kotlin/text/regex/MatchResult.kt", "./libraries/stdlib/src/kotlin/collections/Sequence.kt", )