ReenteringLazyValueComputationException in Kotlin 1.3.20


#1

I’m getting ReenteringLazyValueComputationException when I try to compile the following piece of code (an optimized method for a function that gets called very often). No idea why I would get that - code looks alright?

class FailedValidationResult(
    details: Collection<FailedValidationResult> = emptySet(),
    private val useDetailsOnly: Boolean = false
) {
    val details = details.mapInto { element, output ->
        if (element.useDetailsOnly)
            output.addAll(element.details)
        else
            output.add(element)
    }
}

private inline fun <E> Collection<E>.mapInto(
    action: (element: E, output: MutableCollection<E>) -> Unit
): Collection<E> {
    val result: MutableCollection<E> = ArrayList(this.size)
    this.forEach {
        action(it, result)
    }
    return result
}

#2

Thank you, reported as https://youtrack.jetbrains.com/issue/KT-29876

Workaround: specify type of the property explicitly as Collection<FailedValidationResult>