Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin destructuring variables is not working with Pair, Triple or data class

I've recently tried the following code in kotlinc, command line environment.

var greet = Pair("Hello", "World")
val (word1, word2) = greet

Outputting word1 and word2 in console outputs the below message

>>> word1
error: unresolved reference: word1
word1
^

I'm not sure if de-structuring is being removed from the latest version of kotlin. Currently, using 1.0.2 version of kotlinc compiler on mac.

like image 463
Piyush Chauhan Avatar asked Mar 11 '23 23:03

Piyush Chauhan


1 Answers

This is a known limitation in the Kotlin REPL. Destructuring declarations work fine in the source code (.kt files).

Here's the issue in the bug tracker: https://youtrack.jetbrains.com/issue/KT-5620

like image 162
Alexander Udalov Avatar answered Mar 16 '23 04:03

Alexander Udalov