Paul Krill
Editor at Large

Kotlin previews support for coroutine stack trace recovery

news
Jul 27, 20263 mins

Kotlin 2.4.20-Beta2 also brings Wasm changes, new Swift export features, a DSL for browser testing, and the debut of the Kotlin compiler native image.

Java / coffee
Credit: Robert Shunev

JetBrains has released Kotlin 2.4.20-Beta2, an update to the company’s multiplatform programming language that has emerged with capabilities ranging from the Wasmtime runtime to JavaScript functions and Swift accommodations.

Kotlin 2.4.20-Beta2 was released July 2. Among the new capabilities and improvements, the new release changes how Kotlin/Wasm handles top-level require() calls in @JsFun declarations, aligns companion object initialization order with JVM behavior, and supports Wasmtime as a runtime for thewasmWasi target in the Kotlin Gradle plugin. Kotlin/Wasm now initializes superclass companion objects before subclass companion objects, matching the JVM behavior. Previously, the initialization could be reversed, leading to inconsistent behavior across platforms.

Kotlin 2.4.20-Beta2 also introduces cross-language inheritance support to Swift export. A common use case for this feature is the reverse import pattern, where developers define a contract in Kotlin and provide platform-specific implementations on the Swift side. And for Kotlin/JS, Kotlin 2.4.20-Beta2 introduces an experimental DSL for browser testing and support for exporting suspend lambdas as JavaScript async functions. Previously, there was no way to export declarations containing suspend lambdas from Kotlin/JS libraries. Now, the Kotlin compiler automatically handles the bridging between Kotlin’s suspend functions and native JavaScript’s async/await model. This is useful for mixed Kotlin/TypeScript codebases, JetBrains said.

Kotlin 2.4.20-Beta2 introduces support for coroutine stack trace recovery, with the addition of the StackTraceRecoverable interface to the standard library. This feature, currently experimental, improves integration with the kotlinx.coroutines library because it allows developers to create new exception instances for stack trace recovery without adding a dependency on kotlinx.coroutines, according to JetBrains. Stack trace recovery helps with debugging when one coroutine throws an exception, and another rethrows it. It lets developers see where the exception originates and where another coroutine rethrows it.

Also experimental are four new functions that check collection elements for equality and uniqueness. The functions .allDistinct(), .allDistinctBy(), .allEqual(), and .allEqualBy() can be used on collections, sequences, and arrays, and compare elements using structural equality like other collection operations. Until these functions arrived in Kotlin 2.4.20-Beta2, checking whether collection elements were all distinct or all equal required using inefficient code patterns, JetBrains said.

And Kotlin 2.4.20-Beta2 features the first release of the Kotlin compiler native image. The native image offers a drop-in replacement for the standard kotlinc command-line tool, while offering faster startup time and higher performance, JetBrains said. This feature is also experimental.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author