summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonid Startsev <sandwwraith@users.noreply.github.com>2024-05-06 18:24:16 +0200
committerGitHub <noreply@github.com>2024-05-06 18:24:16 +0200
commit84a21717f2f30b896783f273119e7f14231a2556 (patch)
treecc0c67f7a60747ebe802d1ae00f66ea28c883009
parent251bca77242f7c9d61912b582d82b5f358993f6d (diff)
downloadkotlinx.serialization-84a21717f2f30b896783f273119e7f14231a2556.tar.gz
Rewrite obsolete forgotten intrinsic test (#2647)
that should be part of da020f9730ffbac18b380ef25f9a9a3e09745946 (#2642) commit. See that commit message for reasoning.
-rw-r--r--core/jvmTest/src/kotlinx/serialization/CachingTest.kt17
-rw-r--r--formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt14
2 files changed, 17 insertions, 14 deletions
diff --git a/core/jvmTest/src/kotlinx/serialization/CachingTest.kt b/core/jvmTest/src/kotlinx/serialization/CachingTest.kt
index 686ac473..634fb007 100644
--- a/core/jvmTest/src/kotlinx/serialization/CachingTest.kt
+++ b/core/jvmTest/src/kotlinx/serialization/CachingTest.kt
@@ -60,4 +60,21 @@ class CachingTest {
val ser3 = serializer(typeOf<Target>())
assertTrue(SERIALIZERS_CACHE.isStored(Target::class), "Serializer should be stored in cache after typeOf-based lookup")
}
+
+ @Serializable
+ class Target2
+
+ inline fun <reified T : Any> indirect(): KSerializer<T> = serializer<T>()
+
+ @Test
+ fun testJvmIntrinsicsIndirect() {
+ val ser1 = Target2.serializer()
+ assertFalse(SERIALIZERS_CACHE.isStored(Target2::class), "Cache shouldn't have values before call to serializer<T>()")
+ val ser2 = indirect<Target2>()
+ assertFalse(
+ SERIALIZERS_CACHE.isStored(Target2::class),
+ "Serializer for Target2::class is stored in the cache, which means that runtime lookup was performed and call to serializer<Target2> was not intrinsified." +
+ "Check that compiler plugin intrinsics are enabled and working correctly."
+ )
+ }
}
diff --git a/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt b/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt
index a600b9d7..94a83fda 100644
--- a/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt
+++ b/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt
@@ -275,18 +275,4 @@ class SerializerByTypeTest {
serializer(typeTokenOf<Array<NonSerializable>>())
}
}
-
- @OptIn(ExperimentalTime::class)
- @Test
- fun testSerializersAreIntrinsified() {
- val direct = measureTime {
- Json.encodeToString(IntData.serializer(), IntData(10))
- }
- val directMs = direct.inWholeMicroseconds
- val indirect = measureTime {
- Json.encodeToString(IntData(10))
- }
- val indirectMs = indirect.inWholeMicroseconds
- if (indirectMs > directMs + (directMs / 4)) error("Direct ($directMs) and indirect ($indirectMs) times are too far apart")
- }
}