Skip to content

Commit

Permalink
Minor, move decodeDuration logic to a function reference (Kotlin#2550)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
udalov committed Jan 25, 2024
1 parent 8a3ed23 commit 41c0bb1
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 41c0bb1

Please sign in to comment.