diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index 28b734cbd57f1..b1b2b7c86c182 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -1343,7 +1343,7 @@ public fun Iterable.toList(): List { if (this is Collection) { return when (size) { 0 -> emptyList() - 1 -> listOf(if (this is List) get(0) else iterator().next()) + 1 -> if (this is List) listOf(get(0)) else (iterator().takeIf { it.hasNext() }?.next()?.let(::listOf) ?: emptyList()) else -> this.toMutableList() } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt index f226002f1c65a..744cd1b0d0eb5 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt @@ -167,7 +167,7 @@ object Snapshots : TemplateGroupBase() { if (this is Collection) { return when (size) { 0 -> emptyList() - 1 -> listOf(if (this is List) get(0) else iterator().next()) + 1 -> if (this is List) listOf(get(0)) else (iterator().takeIf { it.hasNext() }?.next()?.let(::listOf) ?: emptyList()) else -> this.toMutableList() } }