summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Udalov <udalov@users.noreply.github.com>2024-01-25 11:27:53 +0100
committerGitHub <noreply@github.com>2024-01-25 11:27:53 +0100
commit41c0bb10bcb04bb8c72828b0b5fe63ab85a348f5 (patch)
tree26e3829ad13b50126cdbb535001cff504247cefd
parent8a3ed23827c34920f6cd191c1e1806f2128ad50e (diff)
downloadkotlinx.serialization-41c0bb10bcb04bb8c72828b0b5fe63ab85a348f5.tar.gz
Minor, move decodeDuration logic to a function reference (#2550)
This is needed because once we enable indy lambdas by default (KT-45375), `@SuppressAnimalSniffer` annotation stops working, because animalsnifferMain does not handle indy lambdas correctly, and the `animalsnifferMain` task reports several errors about `java.time.Duration` being used. There are multiple ways to workaround this issue, for example we could annotate the lambda with `@JvmSerializableLambda` or compile the whole module with `-Xlambdas=class`, but I chose to use a simple function reference instead, since we don't generate those via invokedynamic yet (KT-45658), and it doesn't make the code any more difficult.
-rw-r--r--formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt10
1 files changed, 6 insertions, 4 deletions
diff --git a/formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt b/formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt
index 5ca445ec..163e5627 100644
--- a/formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt
+++ b/formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt
@@ -109,11 +109,13 @@ public sealed class Hocon(
private fun getTaggedNumber(tag: T) = validateAndCast<Number>(tag)
+ @Suppress("UNCHECKED_CAST")
+ protected fun <E> decodeDuration(tag: T): E =
+ getValueFromTaggedConfig(tag, ::decodeDurationImpl) as E
+
@SuppressAnimalSniffer
- protected fun <E> decodeDuration(tag: T): E {
- @Suppress("UNCHECKED_CAST")
- return getValueFromTaggedConfig(tag) { conf, path -> conf.decodeJavaDuration(path).toKotlinDuration() } as E
- }
+ private fun decodeDurationImpl(conf: Config, path: String): Duration =
+ conf.decodeJavaDuration(path).toKotlinDuration()
override fun decodeTaggedString(tag: T) = validateAndCast<String>(tag)