Hi, can someone suggest with freeze() method. Is i...
# multiplatform
v
Hi, can someone suggest with freeze() method. Is it a bug or I do something wrong: I create instance of Kotlin data class from Swift. Then I pass this instance to Kotlin code, where I call freeze() for passing it to another thread. Per documentation freeze() should freeze this instance and its subgraph. But I found that It freezes only itself. Subgraph stays untouched and not frozen. Example:
Copy code
data class Foo(val bars: List<Bar>)

// create instance of Foo with bars on Swift side and pass it to some Kotlin Multiplatform class where I call
foo.freeze()
// now I expect that bars are frozen, but they are not
// as a workaround I use
foo.bars.forEach { it.freeze() }
When I do the same purely in Kotlin - everything works as expected, instance of Foo is frozen and all its properties
a
Hello, can you please file an issue on kotl.in/issue with a project to reproduce this behaviour?
v
Hello @Artyom Degtyarev [JB]. I've created https://youtrack.jetbrains.com/issue/KT-44108
n
I hit this yesterday. I wonder if there’s a blessed workaround? One idea I came up with is use KotlinArray instead of a List to get deep-freezing as expected. cc @svyatoslav.scherbina sorry for tagging but you commented on the ticket 🙏
s
One idea I came up with is use KotlinArray instead of a List to get deep-freezing as expected.
This should work. Alternatively, you can instantiate a List in Kotlin. In particular, creating Swift array (in Swift) and copying it in Kotlin with
.toList()
should work.
🙏 1