https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • a

    Amritansh

    02/08/2021, 7:41 PM
    Hi, My iOSFramework size is ~15mb when generated using kotlin multiplatform. Not sure if it is normal to have large framework file size since it looks like it is on a higher side.
    m
    k
    k
    • 4
    • 18
  • p

    Paul Woitaschek

    02/09/2021, 5:32 PM
    Which folders of .konan would you cache on a ci server?
    b
    • 2
    • 2
  • p

    Peter Tran

    02/10/2021, 12:00 AM
    Hi, I have a question about native C consuming a KN shared lib. I am reviewing the code in the 'produce_dynamic' test and noticed this: https://github.com/JetBrains/kotlin-native/blob/master/backend.native/tests/produce_dynamic/simple/main.c#L38
    T_(Data) data = __ kotlin.root.getMutable();
    Why is this object not released via
    DisposeStablePointer()
    like the other objects returned from the KN side? (@olonho/@svyatoslav.scherbina ?)
    s
    • 2
    • 4
  • p

    Paul Woitaschek

    02/10/2021, 7:32 AM
    Is it possible to remove a target? I use the
    watchos
    shortcut but don't want the new
    watchosx64
    that gets added on 1.3.0 because the stable versions of serialization and ktor don't support it yet.
    k
    • 2
    • 1
  • a

    Andrey Logoshko

    02/11/2021, 1:38 PM
    Hey guys, I just came across at this zephyr repo. I know that kotlin-native doesn't support [no-std] targets out of the box, but is there a way to configure it (since it uses LLVM under the hood anyways)? What I'm talking about is something like Creating Custom Targets for Rust guidelines.
    m
    • 2
    • 1
  • a

    aleksey.tomin

    02/17/2021, 1:19 PM
    After migrate I’ve had a problem. macOS target
    e: Compilation failed: Backend Internal error: Exception during IR lowering
    File being compiled: /Users/atomin/Documents/iq/xpoint-sdk/sdk/src/commonMain/kotlin/com/inventale/xpoint/sdk/Checker.kt
    The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy.fakeOverrideMember(IrOverridingUtil.kt:43)
    
     * Source files: 
     * Compiler version info: Konan: 1.4.30 / Kotlin: 1.4.30
     * Output kind: PROGRAM
    
    e: org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
    File being compiled: /Users/atomin/Documents/iq/xpoint-sdk/sdk/src/commonMain/kotlin/com/inventale/xpoint/sdk/Checker.kt
    The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy.fakeOverrideMember(IrOverridingUtil.kt:43)
            at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:239)
            at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException$default(CodegenUtil.kt:235)
            at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invoke(PhaseBuilders.kt:124)
    ...
    Caused by: java.lang.AssertionError: Unexpected variance in super type argument: in @0
            at org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy.fakeOverrideMember(IrOverridingUtil.kt:43)
            at org.jetbrains.kotlin.ir.overrides.IrOverridingUtil.buildFakeOverridesForClassUsingOverriddenSymbols(IrOverridingUtil.kt:168)
            at org.jetbrains.kotlin.backend.common.ir.IrUtilsKt.addFakeOverrides(IrUtils.kt:487)
            at org.jetbrains.kotlin.backend.common.ir.IrUtilsKt.addFakeOverrides$default(IrUtils.kt:485)
    I can’t share project source. How can I fix the problem?
    e
    p
    • 3
    • 6
  • t

    tieskedh

    02/17/2021, 7:27 PM
    question, is is possible to retrieve data already stored in NSData using pure kotlin common and a library? I'm not an IOS-developer, but I want to convince to switch...
    j
    s
    • 3
    • 2
  • s

    salomonbrys

    02/19/2021, 3:10 PM
    Is there a way to set the Konan
    osVersionMin.ios_x64
    and
    osVersionMin.ios_arm64
    on a per-project basis (rather in
    ~/.konan
    ) ?
    r
    l
    • 3
    • 28
  • j

    JoakimForslund

    02/21/2021, 10:13 AM
    Anyone have any clue as to why SDL_CreateThread is set as deprecated and can not be used in the https://github.com/JetBrains/kotlin-native/tree/master/samples/tetris example under windows with mingwx64?
    • 1
    • 3
  • d

    Dave Trollope

    02/21/2021, 6:51 PM
    What is the correct way to start a new app based off the samples in https://github.com/JetBrains/kotlin-native/issues?q=is%3Aissue+is%3Aopen+ ? I successfully built and ran the UIKit sample in place, and then copied that dir out. However, it relies on the gradlew in the parent dir. What is the expected way to use these samples in a standalone manner? There is a note about building from a dist archive, is the expectation that you unpack a sample archive from the dist dir and build new apps off that? Forgive my inexperience here with gradle and general setup - thus why I'm doing this to learn.
    • 1
    • 1
  • j

    Jeff Tycz

    02/22/2021, 3:45 AM
    I am trying to convert this bit of code into kotlin
    - (NSString *)hmacsha1:(NSString *)data secret:(NSString *)key {
    
        const char *cKey  = [key cStringUsingEncoding:NSASCIIStringEncoding];
        const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];
    
        unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];
    
        CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
    
        NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
    
        NSString *hash = [HMAC base64String];
    
        return hash;
    }
    This is currently what I have
    actual fun generateHmacSha1Signature(key: String, value: String): String = memScoped{
        val nsKey = NSString.create(string = key)
        val nsValue = NSString.create(string = value)
        val encodedKey = nsKey.cStringUsingEncoding(NSUTF16StringEncoding)
        val encodedValue = nsValue.cStringUsingEncoding(NSUTF16StringEncoding)
    
        val cHMAC = ByteArray(CC_SHA1_DIGEST_LENGTH)
    
        CCHmac(kCCHmacAlgSHA1, encodedKey, strlen(encodedKey?.toKString()), encodedValue, strlen(encodedValue?.toKString()), cHMAC.asUByteArray().toCValues())
    
        val data:NSData = NSData.create(bytes = allocArrayOf(cHMAC), length = cHMAC.size.toULong())
    
        return data.base64EncodedStringWithOptions(NSDataBase64DecodingIgnoreUnknownCharacters)
    }
    The problem with what I have though is that it does not seem to be generating a correct SHA1 signature. I get
    AAAAAAAAAAAAAAAAAAAAAAAAAAA=
    as a value when I use it. The part that don't think is correct is the
    CCHmac
    because I was not sure if I was getting the string length correctly and the
    cHMAC
    ByteArray correctly. Can anyone tell me where I went wrong?
    t
    • 2
    • 2
  • b

    Brian Dilley

    02/22/2021, 4:50 AM
    What’s the future of KotlinNative? Are any platform libraries planned for the future? (ie: accessing files and things of that sort). I’d love to use Kotlin as an alternative to C/C++/Go/Rust
    d
    • 2
    • 7
  • m

    Matthieu Stombellini

    02/22/2021, 1:27 PM
    Hello, I just started using Kotlin/Native and I'm a bit confused with how I can turn a CValue<T> into T. I know useContents exist but is there a more practical way of doing this?
    val result: CValue<Thing> = my_c_function_call()
    val resultButRealThisTime: Thing = ???
    Doing
    val result = my_c_function_call()
    val resultButReal: Thing? = null
    result.useContents { resultButReal = this@useContents }
    Works, but looks awful and I don't think that's how you're supposed to do that
    r
    m
    d
    • 4
    • 6
  • u

    utikeev

    02/22/2021, 11:01 PM
    Hello! I'm looking into Kotlin/Native and wanted to use
    cglm
    library (https://github.com/recp/cglm) for supporting OpenGL maths. Though, I have some problems with it. Details in :thread-please:.
    d
    • 2
    • 4
  • c

    Clocks

    02/23/2021, 5:48 AM
    Hello! I'm working on a GTK library in kotlin native. It's been difficult as I have been mostly stumbling upon solutions at random. I have the following code
    val int1: CValue<IntVarOf<Int>> = cValue()
    val int2: CValue<IntVarOf<Int>> = cValue()
    
    gtk_window_get_default_size(
    	window = windowPointer,
    	width = int1,
    	height = int2
    )
    gtk_window_get_default_size
    takes in a pointer to the window, then a pointer to `Int`s that it will populate. How can I get the
    Int
    out of
    CValue<IntVarOf<Int>>
    ?
    ✅ 1
    a
    b
    • 3
    • 6
  • n

    nirazo

    02/25/2021, 10:11 AM
    Hello! On my project, I make UseCases in Kotlin and execute UseCase’s
    execute
    method from APP to get value. The return values from UseCases are defined as Results, and puts it in Output of UseCase, and returns it to my APP. Define of Results:
    sealed class Results<out T, out S> {
        class Success<out T>(val data: T) : Results<T, Nothing>()
        class Failure<out S>(val cause: S) : Results<Nothing, S>()
    }
    Sample useCase and it’s IO:
    interface SampleUseCaseInterface {
        suspend fun execute(): sampleUseCaseIO.Output
    }
    
    class sampleUseCase() : SampleUseCaseInterface {
        override suspend fun execute(): sampleUseCaseIO.Output =
            sampleUseCaseIO.Output(Results.Success("success!"))
    }
    
    class sampleUseCaseIO {
        data class Output(val results: Results<String, Error>)
    }
    Now, I want to mock the execute method of UseCase and return an arbitrary Output in order to write a Unit Test in an iOS app. However, now the following error is displayed and it is not possible to create an arbitrary output. Both data and error are required to be included in Results, and the required Output cannot be created. Is there any way to avoid this? Also, is it possible to realize a mechanism like Either on the iOS side with Kotlin/Native?
    e
    • 2
    • 2
  • c

    Casey Brooks

    02/25/2021, 8:01 PM
    Is it possible to consume Swift Packages (XCFramework) with the MPP Cocoapods plugin?
    k
    j
    • 3
    • 4
  • k

    Ky Leggiero

    02/27/2021, 11:24 PM
    This true?
    :yes: 1
    e
    d
    +3
    • 6
    • 16
  • d

    darkmoon_uk

    03/01/2021, 1:11 AM
    Is there any general guidance on debugging`kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen` issues? I'm getting this upon instantiating a class; during static initialisation! I cannot see how on earth this is 'concurrent' modification when the object is just in the process of being initialised itself 😞
    e
    • 2
    • 1
  • a

    aleksey.tomin

    03/01/2021, 12:12 PM
    I try to notarize my macOS application. I’ve done
    codesign -dvv --force --timestamp --sign ***
    for all dylib’s and my kexe with a
    Mac App Distribution
    certificate Next I’ve signed
    productsign --sign
    and
    codesign -dvv --force --timestamp --sign
    with a
    Mac Installer Distribution
    certificate And the last:
    xcrun altool --notarize-app --primary-bundle-id "ID"
    - AppID configuration. After this in the log I see
    {
          "severity": "error",
          "code": null,
          "path": "MY.pkg xpoint-sdk.kexe",
          "message": "The binary is not signed with a valid Developer ID certificate.",
          "docUrl": null,
          "architecture": "x86_64"
        },
       {
          "severity": "error",
          "code": null,
          "path": "MY.pkg .../xpoint-sdk.kexe",
          "message": "The executable does not have the hardened runtime enabled.",
          "docUrl": null,
          "architecture": "x86_64"
        }
    ...
       {
          "severity": "error",
          "code": null,
          "path": "MY.pkg .../some.dylib",
          "message": "The binary is not signed with a valid Developer ID certificate.",
          "docUrl": null,
          "architecture": "x86_64"
        }
    How can I fix it?
    o
    • 2
    • 5
  • i

    Iaroslav Postovalov

    03/01/2021, 6:18 PM
    Hi! Any example of receiving a function pointer with Kotlin method?
    a
    • 2
    • 3
  • i

    Iaroslav Postovalov

    03/01/2021, 6:27 PM
    And how can I use ByteArray?
    e: /home/commandertvis/IdeaProjects/communicator/communicator-zmq-c-transport/src/nativeMain/kotlin/Server.kt: (22, 43): type @[ParameterName(name = 'argument')] kotlin.ByteArray  is not supported here: doesn't correspond to any C type
    a
    • 2
    • 12
  • a

    arnaud.giuliani

    03/02/2021, 3:54 PM
    Is it a Native only behavior, or is it temporary?
    e
    • 2
    • 2
  • d

    darkmoon_uk

    03/03/2021, 11:57 AM
    Any advice for debugging:
    Uncaught Kotlin exception: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[WorkerCoroutineDispatcherImpl@d81448, Continuation @ $collect_2COROUTINE$220]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
    This is when one of my Flows ends; everything is in the main thread... 😱
    t
    d
    • 3
    • 6
  • j

    John O'Reilly

    03/03/2021, 12:18 PM
    Just saw that Kotlinx Coroutines 1.4.3 has been released (https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.4.3) ....usual follow on question re. when
    native-mt
    version will be available? 🙂
    👀 4
    a
    • 2
    • 3
  • s

    sergey.bogolepov

    03/04/2021, 7:11 AM
    Hello everyone! As some of you might know, in 1.3.70 we added support for compiler caches for
    macosX64
    and
    iosX64
    targets. Long story short, compiler caches make compilation time of debug builds (e.g.
    linkDebug...
    ) in Gradle significantly faster (well, except the first one, when dependencies are caching and Gradle daemon is warming up). In 1.5.0-M1 we add opt-in support for compiler caches for two more targets: •
    iosArm64
    •
    linuxX64
    (only on Linux host) To enable them add a single line to your
    gradle.properties
    . For
    linuxX64
    target:
    kotlin.native.cacheKind.linuxX64=static
    For
    iosArm64
    target:
    kotlin.native.cacheKind.iosArm64=static
    "Why not enable it by default?" you might ask. While it doesn't break our test projects, it might break yours. And who likes broken compilation after compiler update? :) So, we asking you to test compiler caches on your projects and report to us if you encounter any kind of problems. Let's make Kotlin faster together!
    👍 8
    n
    • 2
    • 3
  • p

    Paul Woitaschek

    03/04/2021, 1:33 PM
    I ran into real weirdnesses with an combined apple source set for watchos and ios because the NSInteger is a long on ios and an int on watchos. This made me write really strange code like this:
    internal fun NSInteger.toInt(): Int {
      return asInt()
    }
    
    private fun Any.asInt(): Int {
      return when (this) {
        is Long -> this.toInt()
        is Int -> this
        else -> error("Could not convert $this to Int")
      }
    }
    Is there a better way to do that? I’m kind of looking for the opposite of cinterop.convert.
    m
    r
    • 3
    • 5
  • s

    serebit

    03/04/2021, 4:13 PM
    Will Kotlin/Native's 1.5-M1 tag be getting release notes?
    o
    • 2
    • 8
  • p

    Paul Woitaschek

    03/05/2021, 6:03 AM
    I still don’t understand the types of kotlin native. According to this table https://github.com/JetBrains/kotlin/blob/06498c0efdb218da4bd1b09b6ae0b98beb8b7af9/native/utils/src/org/jetbrains/kotlin/konan/target/KonanTarget.kt
    ...
        object WATCHOS_ARM32 : KonanTarget("watchos_arm32", Family.WATCHOS, Architecture.ARM32)
        object WATCHOS_ARM64 : KonanTarget("watchos_arm64", Family.WATCHOS, Architecture.ARM64)
    ...
    And this https://github.com/JetBrains/kotlin/blob/06498c0efdb218da4bd1b09b6ae0b98beb8b7af9/native/utils/src/org/jetbrains/kotlin/konan/target/Architecture.kt
    enum class Architecture(val bitness: Int) {
     ...
        ARM64(64),
        ARM32(32)
    ,...
    }
    watchosarm32 is 32 bit and watchosarm64 is 64 bit. However when I now take a look at my
    watchosArm32Main
    source set, for example
    NSDateComponents
    have `NSInteger`s which will be interpreted as kotlin ints. Makes sense to me. Now however in
    watchosArm64Main
    it’s also an Int. Why is that? Why isn’t this now a
    Long
    ? Apparently all ios source sets have longs, all watchos source sets have ints. I thought this is dependent on the bitness?
    s
    • 2
    • 3
  • w

    william

    03/07/2021, 8:58 PM
    Hi all I am having trouble with an object getting frozen in its
    init
    block and then top level value assignments causing an exception. heres a min example:
    class Foo(bar: Bar) {
        init {
            CoroutineScope(Dispatchers.Default).launch { 
                bar.buzz()
            }
        }
        
        val a = 3
    }
    in the init block since bar is accessed, it seems like that is causing the entire foo object to also get frozen then when it gets to
    val a = 3
    during runtime - it complains about foo instance already being frozen. how can i go about fixing this?
    t
    • 2
    • 3
Powered by Linen
Title
w

william

03/07/2021, 8:58 PM
Hi all I am having trouble with an object getting frozen in its
init
block and then top level value assignments causing an exception. heres a min example:
class Foo(bar: Bar) {
    init {
        CoroutineScope(Dispatchers.Default).launch { 
            bar.buzz()
        }
    }
    
    val a = 3
}
in the init block since bar is accessed, it seems like that is causing the entire foo object to also get frozen then when it gets to
val a = 3
during runtime - it complains about foo instance already being frozen. how can i go about fixing this?
got help in #multiplatform
t

Tijl

03/08/2021, 7:28 AM
class Foo(bar: Bar) {
    init {
        val bar = bar
CoroutineScope(Dispatchers.Default).launch { 
            bar.buzz()
        }
    }
    val a = 3
}
get it into local scope
View count: 8