Skip to content

Commit 41c0bb1

Browse files
authored
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.
1 parent 8a3ed23 commit 41c0bb1

File tree

1 file changed

+6
-4
lines changed
  • formats/hocon/src/main/kotlin/kotlinx/serialization/hocon

1 file changed

+6
-4
lines changed

formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ public sealed class Hocon(
109109

110110
private fun getTaggedNumber(tag: T) = validateAndCast<Number>(tag)
111111

112+
@Suppress("UNCHECKED_CAST")
113+
protected fun <E> decodeDuration(tag: T): E =
114+
getValueFromTaggedConfig(tag, ::decodeDurationImpl) as E
115+
112116
@SuppressAnimalSniffer
113-
protected fun <E> decodeDuration(tag: T): E {
114-
@Suppress("UNCHECKED_CAST")
115-
return getValueFromTaggedConfig(tag) { conf, path -> conf.decodeJavaDuration(path).toKotlinDuration() } as E
116-
}
117+
private fun decodeDurationImpl(conf: Config, path: String): Duration =
118+
conf.decodeJavaDuration(path).toKotlinDuration()
117119

118120
override fun decodeTaggedString(tag: T) = validateAndCast<String>(tag)
119121

0 commit comments

Comments
 (0)