JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.25k stars 1.18k forks source link

[iOS] Composable functions returning null cause crash #3900

Closed alexzhirkevich closed 11 months ago

alexzhirkevich commented 1 year ago

Describe the bug Composable functions (and properties) returning null cause crash

Affected platforms Select one of the platforms below:

Versions

To Reproduce

@Composable
fun test() : Int? = null //crash when called

Should be p:high i think as it can result in unexpected random EXC_BREAKPOINT crashes without normal description (I personally spend a long time finding a reason)

@Composable
fun test(condition : Boolean) : Int? {
    return if (condition)
        1337
    else null // crash
}
Trace ``` ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Incident Identifier: 7973F156-D0E1-4D97-910E-D105B607813A CrashReporter Key: 34688A7D-090D-0E5E-A740-0E61C6315293 Hardware Model: MacBookAir10,1 Process: My application [17024] Path: /Users/USER/Library/Developer/CoreSimulator/Devices/A2FE2CCC-44AF-4EFC-9646-3D0DC306E624/data/Containers/Bundle/Application/2D813892-654E-48A6-9F1D-31789E9343E3/My application.app/My application Identifier: com.example Version: 1.0 (1) Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd_sim [1054] Coalition: com.apple.CoreSimulator.SimDevice.A2FE2CCC-44AF-4EFC-9646-3D0DC306E624 [63477] Responsible Process: SimulatorTrampoline [97317] Date/Time: 2023-11-04 02:35:13.5597 +0300 Launch Time: 2023-11-04 02:35:13.2732 +0300 OS Version: macOS 14.0 (23A344) Release Type: User Report Version: 104 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x00000001050734a4 Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [17024] Triggered by Thread: 0 Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 shared 0x1050734a4 kfun:#test(androidx.compose.runtime.Composer?;kotlin.Int){}kotlin.Int? + 372 1 shared 0x10502419c kfun:#App(androidx.compose.runtime.Composer?;kotlin.Int){} + 916 (App.kt:110) 2 shared 0x105073874 kfun:ComposableSingletons$Main_iosKt.$lambda$0#internal + 408 (main.ios.kt:22) 3 shared 0x105073944 kfun:ComposableSingletons$Main_iosKt.$$lambda$0$FUNCTION_REFERENCE$1.invoke#internal + 96 (main.ios.kt:21) 4 shared 0x1050739f8 kfun:ComposableSingletons$Main_iosKt.$$lambda$0$FUNCTION_REFERENCE$1.$invoke(androidx.compose.runtime.Composer;kotlin.Int){}#internal + 160 (main.ios.kt:21) 5 shared 0x105286be8 kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 116 ([K][Suspend]Functions:1) 6 shared 0x1054ac060 kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 588 (ComposableLambda.native.kt:108) 7 shared 0x1054b9a30 kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#$invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any?(androidx.compose.runtime.Composer;kotlin.Any?){}kotlin.Any? + 164 (ComposableLambda.native.kt:33) 8 shared 0x105286be8 kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 116 ([K][Suspend]Functions:1) 9 shared 0x1053e6b4c kfun:androidx.compose.runtime#CompositionLocalProvider(kotlin.Array>...;kotlin.Function2;androidx.compose.runtime.Composer?;kotlin.Int){} + 596 (CompositionLocal.kt:228) 10 shared 0x105e50144 kfun:androidx.compose.ui.window.ComposeWindow.attachComposeIfNeeded$lambda$11#internal + 1980 (ComposeWindow.uikit.kt:679) 11 shared 0x105e573c0 kfun:androidx.compose.ui.window.ComposeWindow.$attachComposeIfNeeded$lambda$11$FUNCTION_REFERENCE$20.invoke#internal + 124 (ComposeWindow.uikit.kt:677) 12 shared 0x105e57540 kfun:androidx.compose.ui.window.ComposeWindow.$attachComposeIfNeeded$lambda$11$FUNCTION_REFERENCE$20.$invoke(androidx.compose.runtime.Composer;kotlin.Int){}#internal + 160 (ComposeWindow.uikit.kt:677) 13 shared 0x105286be8 kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 116 ([K][Suspend]Functions:1) 14 shared 0x1054ac060 kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 588 (ComposableLambda.native.kt:108) 15 shared 0x1054b9a30 kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#$invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any?(androidx.compose.runtime.Composer;kotlin.Any?){}kotlin.Any? + 164 (ComposableLambda.native.kt:33) 16 shared 0x105286be8 kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 116 ([K][Suspend]Functions:1) 17 shared 0x1053e6b4c kfun:androidx.compose.runtime#CompositionLocalProvider(kotlin.Array>...;kotlin.Function2;androidx.compose.runtime.Composer?;kotlin.Int){} + 596 (CompositionLocal.kt:228) 18 shared 0x105e00018 kfun:androidx.compose.ui.ComposeScene.setContent$lambda$9#internal + 732 (ComposeScene.skiko.kt:474) 19 shared 0x105e01124 kfun:androidx.compose.ui.ComposeScene.$setContent$lambda$9$FUNCTION_REFERENCE$17.invoke#internal + 120 (ComposeScene.skiko.kt:473) 20 shared 0x105e01278 kfun:androidx.compose.ui.ComposeScene.$setContent$lambda$9$FUNCTION_REFERENCE$17.$invoke(androidx.compose.runtime.Composer;kotlin.Int){}#internal + 160 (ComposeScene.skiko.kt:473) 21 shared 0x105286be8 kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 116 ([K][Suspend]Functions:1) 22 shared 0x1054ac060 kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 588 (ComposableLambda.native.kt:108) 23 shared 0x1054b9a30 kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#$invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any?(androidx.compose.runtime.Composer;kotlin.Any?){}kotlin.Any? + 164 (ComposableLambda.native.kt:33) 24 shared 0x105286be8 kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 116 ([K][Suspend]Functions:1) 25 shared 0x1053e6b4c kfun:androidx.compose.runtime#CompositionLocalProvider(kotlin.Array>...;kotlin.Function2;androidx.compose.runtime.Composer?;kotlin.Int){} + 596 (CompositionLocal.kt:228) 26 shared 0x105dce468 kfun:androidx.compose.ui.platform#ProvideCommonCompositionLocals(androidx.compose.ui.node.Owner;androidx.compose.ui.platform.UriHandler;kotlin.Function2;androidx.compose.runtime.Composer?;kotlin.Int){} + 3780 (CompositionLocals.kt:195) 27 shared 0x105dcf074 kfun:androidx.compose.ui.platform.ProvideCommonCompositionLocals$lambda$18#internal + 284 28 shared 0x105dcf930 kfun:androidx.compose.ui.platform.$ProvideCommonCompositionLocals$lambda$18$FUNCTION_REFERENCE$18.invoke#internal + 128 29 shared 0x105dcfacc kfun:androidx.compose.ui.platform.$ProvideCommonCompositionLocals$lambda$18$FUNCTION_REFERENCE$18.$invoke(androidx.compose.runtime.Composer?;kotlin.Int){}#internal + 160 30 shared 0x105286be8 kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 116 ([K][Suspend]Functions:1) 31 shared 0x1053f2420 kfun:androidx.compose.runtime.RecomposeScopeImpl#compose(androidx.compose.runtime.Composer){} + 356 (RecomposeScopeImpl.kt:169) 32 shared 0x1053bb764 kfun:androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd#internal + 1276 (Composer.kt:2469) 33 shared 0x1053bd8d0 kfun:androidx.compose.runtime.ComposerImpl#skipCurrentGroup(){} + 480 (Composer.kt:2738) 34 shared 0x1053c25d4 > + 608 (Composer.kt:3353) [inlined] 35 shared 0x1053c25d4 kfun:androidx.compose.runtime#observeDerivedStateRecalculations(androidx.compose.runtime.DerivedStateObserver;kotlin.Function0<0:0>){0§} + 660 (DerivedState.kt:381) [inlined] 36 shared 0x1053c25d4 > + 1208 (Composer.kt:3338) [inlined] 37 shared 0x1053c25d4 + 1700 (Trace.kt:48) [inlined] 38 shared 0x1053c25d4 kfun:androidx.compose.runtime.ComposerImpl.doCompose#internal + 2464 (Composer.kt:3315) 39 shared 0x1053c1ba0 kfun:androidx.compose.runtime.ComposerImpl#recompose(androidx.compose.runtime.collection.IdentityArrayMap?>){}kotlin.Boolean + 552 (Composer.kt:3304) 40 shared 0x1053ddba0 > + 32 (Composition.kt:781) [inlined] 41 shared 0x1053ddba0 + 32 (Composition.kt:883) [inlined] 42 shared 0x1053ddba0 > + 100 (Composition.kt:780) [inlined] 43 shared 0x1053ddba0 + 104 (Composition.kt:1047) [inlined] 44 shared 0x1053ddba0 + 124 (Composition.kt:892) [inlined] 45 shared 0x1053ddba0 > + 160 (Composition.kt:779) [inlined] 46 shared 0x1053ddba0 kfun:kotlinx.atomicfu.locks#synchronized(kotlinx.atomicfu.locks.SynchronizedObject;kotlin.Function0<0:0>){0§}0:0 + 176 (Synchronized.kt:175) [inlined] 47 shared 0x1053ddba0 + 188 (Synchronization.kt:33) [inlined] 48 shared 0x1053ddba0 kfun:androidx.compose.runtime.CompositionImpl#recompose(){}kotlin.Boolean + 600 (Composition.kt:777) 49 shared 0x1054c1420 kfun:androidx.compose.runtime.ControlledComposition#recompose(){}kotlin.Boolean-trampoline + 92 (Composition.kt:160) 50 shared 0x1053fb864 > + 188 (Recomposer.kt:1097) [inlined] 51 shared 0x1053fb864 kfun:androidx.compose.runtime.snapshots.Snapshot#enter(kotlin.Function0<0:0>){0§}0:0 + 436 (Snapshot.kt:132) [inlined] 52 shared 0x1053fb864 + 584 (Recomposer.kt:1166) [inlined] 53 shared 0x1053fb864 kfun:androidx.compose.runtime.Recomposer.performRecompose#internal + 1364 (Recomposer.kt:1089) 54 shared 0x105401144 > + 48 (Recomposer.kt:569) [inlined] 55 shared 0x105401144 + 48 (ListUtils.kt:36) [inlined] 56 shared 0x105401144 > + 744 (Recomposer.kt:567) [inlined] 57 shared 0x105401144 + 816 (Trace.kt:48) [inlined] 58 shared 0x105401144 kfun:androidx.compose.runtime.Recomposer.runRecomposeAndApplyChanges$lambda$4$lambda$3#internal + 2396 (Recomposer.kt:551) 59 shared 0x105405910 kfun:androidx.compose.runtime.Recomposer.$runRecomposeAndApplyChanges$lambda$4$lambda$3$FUNCTION_REFERENCE$13.invoke#internal + 108 (Recomposer.kt:537) 60 shared 0x105405af0 kfun:androidx.compose.runtime.Recomposer.$runRecomposeAndApplyChanges$lambda$4$lambda$3$FUNCTION_REFERENCE$13.$invoke(kotlin.Long){}#internal + 124 (Recomposer.kt:537) 61 shared 0x1052819c0 kfun:kotlin.Function1#invoke(1:0){}1:1-trampoline + 108 ([K][Suspend]Functions:1) 62 shared 0x1053a99b0 > + 52 (BroadcastFrameClock.kt:42) [inlined] 63 shared 0x1053a99b0 kfun:kotlin#runCatching__at__0:0(kotlin.Function1<0:0,0:1>){0§;1§}kotlin.Result<0:1> + 52 (Result.kt:157) [inlined] 64 shared 0x1053a99b0 kfun:androidx.compose.runtime.BroadcastFrameClock.FrameAwaiter.resume#internal + 440 (BroadcastFrameClock.kt:42) 65 shared 0x1053aa284 > + 224 (BroadcastFrameClock.kt:71) [inlined] 66 shared 0x1053aa284 kfun:kotlinx.atomicfu.locks#synchronized(kotlinx.atomicfu.locks.SynchronizedObject;kotlin.Function0<0:0>){0§}0:0 + 244 (Synchronized.kt:175) [inlined] 67 shared 0x1053aa284 + 256 (Synchronization.kt:33) [inlined] 68 shared 0x1053aa284 kfun:androidx.compose.runtime.BroadcastFrameClock#sendFrame(kotlin.Long){} + 500 (BroadcastFrameClock.kt:62) 69 shared 0x105dfb66c > + 64 (ComposeScene.skiko.kt:543) [inlined] 70 shared 0x105dfb66c + 264 (ComposeScene.skiko.kt:186) [inlined] 71 shared 0x105dfb66c kfun:androidx.compose.ui.ComposeScene#render(org.jetbrains.skia.Canvas;kotlin.Long){} + 880 (ComposeScene.skiko.kt:541) 72 shared 0x105e523cc kfun:androidx.compose.ui.window.ComposeWindow.object-2.render#internal + 248 (ComposeWindow.uikit.kt:665) 73 shared 0x105e97960 kfun:androidx.compose.ui.window.SkikoUIViewDelegate#render(org.jetbrains.skia.Canvas;kotlin.Double){}-trampoline + 108 (SkikoUIView.kt:55) 74 shared 0x105e6fb44 kfun:androidx.compose.ui.window.SkikoUIView.object-3.render#internal + 228 (SkikoUIView.kt:92) 75 shared 0x105e973a4 kfun:androidx.compose.ui.window.MetalRedrawerCallbacks#render(org.jetbrains.skia.Canvas;kotlin.Double){}-trampoline + 108 (MetalRedrawer.kt:161) 76 shared 0x105e5fb3c > + 88 (MetalRedrawer.kt:338) [inlined] 77 shared 0x105e5fb3c kfun:kotlin#also__at__0:0(kotlin.Function1<0:0,kotlin.Unit>){0§}0:0 + 88 (Standard.kt:98) [inlined] 78 shared 0x105e5fb3c > + 240 (MetalRedrawer.kt:336) [inlined] 79 shared 0x105e5fb3c kfun:kotlinx.cinterop#autoreleasepool(kotlin.Function0<0:0>){0§}0:0 + 240 (ObjectiveCUtils.kt:13) [inlined] 80 shared 0x105e5fb3c kfun:androidx.compose.ui.window.MetalRedrawer.draw#internal + 2588 (MetalRedrawer.kt:321) 81 shared 0x105e5f098 kfun:androidx.compose.ui.window.MetalRedrawer#drawSynchronously(){} + 204 (MetalRedrawer.kt:313) 82 shared 0x105e675ac kfun:androidx.compose.ui.window.SkikoUIView#objc:layoutSubviews + 3500 (SkikoUIView.kt:226) 83 shared 0x105e73230 _6f72672e6a6574627261696e732e636f6d706f73652e75693a75692f6f70742f6275696c644167656e742f776f726b2f356234626566333562333562396631322f636f6d706f73652f75692f75692f7372632f75696b69744d61696e2f6b6f746c696e2f616e64726f6964782f636f6d706f73652f75692f77696e646f772f536b696b6f5549566965772e6b74_knbridge185 + 144 (SkikoUIView.kt:209) 84 UIKitCore 0x1857cdb1c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1492 85 QuartzCore 0x189f6fdd4 CA::Layer::layout_if_needed(CA::Transaction*) + 440 86 QuartzCore 0x189f7ab30 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 124 87 QuartzCore 0x189e963bc CA::Context::commit_transaction(CA::Transaction*, double, double*) + 460 88 QuartzCore 0x189ec5bf0 CA::Transaction::commit() + 652 89 UIKitCore 0x1852d3504 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 32 90 CoreFoundation 0x1803ee464 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20 91 CoreFoundation 0x1803edbac __CFRunLoopDoBlocks + 352 92 CoreFoundation 0x1803e8450 __CFRunLoopRun + 788 93 CoreFoundation 0x1803e7d28 CFRunLoopRunSpecific + 572 94 GraphicsServices 0x18e7cdbc0 GSEventRunModal + 160 95 UIKitCore 0x1852bafdc -[UIApplication _run] + 868 96 UIKitCore 0x1852bec54 UIApplicationMain + 124 97 SwiftUI 0x1c4b04524 0x1c3c80000 + 15222052 98 SwiftUI 0x1c4b043c4 0x1c3c80000 + 15221700 99 SwiftUI 0x1c4816108 0x1c3c80000 + 12149000 100 My application 0x100affff0 static iOSApp.$main() + 40 101 My application 0x100b000a0 main + 12 (iOSApp.swift:4) 102 dyld_sim 0x100c75558 start_sim + 20 103 dyld 0x100dc6058 start + 2224 Thread 1:: GC Timer thread 0 libsystem_kernel.dylib 0x100bac110 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x101ad3a78 _pthread_cond_wait + 1216 2 libc++.1.dylib 0x1802cc10c std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock&, std::__1::chrono::time_point>>) + 96 3 shared 0x1052dce1c void kotlin::RepeatedTimer::Run::GCSchedulerDataAdaptive(kotlin::gcScheduler::GCSchedulerConfig&, std::__1::function)::'lambda'()>(kotlin::gcScheduler::internal::GCSchedulerDataAdaptive::GCSchedulerDataAdaptive(kotlin::gcScheduler::GCSchedulerConfig&, std::__1::function)::'lambda'()&&) + 556 4 shared 0x1052dd60c void* std::__1::__thread_proxy>, void (*)(kotlin::ScopedThread::attributes, void (kotlin::RepeatedTimer::*&&)(kotlin::gcScheduler::internal::GCSchedulerDataAdaptive::GCSchedulerDataAdaptive(kotlin::gcScheduler::GCSchedulerConfig&, std::__1::function)::'lambda'()&&) noexcept, kotlin::RepeatedTimer*&&, kotlin::gcScheduler::internal::GCSchedulerDataAdaptive::GCSchedulerDataAdaptive(kotlin::gcScheduler::GCSchedulerConfig&, std::__1::function)::'lambda'()&&), kotlin::ScopedThread::attributes, void (kotlin::RepeatedTimer::*)(kotlin::gcScheduler::internal::GCSchedulerDataAdaptive::GCSchedulerDataAdaptive(kotlin::gcScheduler::GCSchedulerConfig&, std::__1::function)::'lambda'()&&) noexcept, kotlin::RepeatedTimer*, kotlin::gcScheduler::internal::GCSchedulerDataAdaptive::GCSchedulerDataAdaptive(kotlin::gcScheduler::GCSchedulerConfig&, std::__1::function)::'lambda'()>>(void*) + 260 5 libsystem_pthread.dylib 0x101ad34c0 _pthread_start + 104 6 libsystem_pthread.dylib 0x101ace6f0 thread_start + 8 Thread 2:: Main GC thread 0 shared 0x1052becf0 kotlin::alloc::FixedBlockPage::Sweep(kotlin::gc::GCHandle::GCSweepScope&, kotlin::alloc::AtomicStack&) + 552 1 shared 0x1052d6c44 kotlin::alloc::PageStore::Sweep(kotlin::gc::GCHandle::GCSweepScope&, kotlin::alloc::AtomicStack&) + 168 2 shared 0x1052d5198 kotlin::alloc::Heap::Sweep(kotlin::gc::GCHandle) + 680 3 shared 0x1052d366c kotlin::gc::ConcurrentMarkAndSweep::PerformFullGC(long long) + 1328 4 shared 0x1052d30f4 kotlin::gc::ConcurrentMarkAndSweep::mainGCThreadBody() + 360 5 shared 0x1052d0dcc void* std::__1::__thread_proxy>, void (*)(kotlin::ScopedThread::attributes, kotlin::ScopedThread (anonymous namespace)::createGCThread(char const*, kotlin::gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep(kotlin::gcScheduler::GCScheduler&, bool, unsigned long)::$_1&&)::'lambda'()&&), kotlin::ScopedThread::attributes, kotlin::ScopedThread (anonymous namespace)::createGCThread(char const*, kotlin::gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep(kotlin::gcScheduler::GCScheduler&, bool, unsigned long)::$_1&&)::'lambda'()>>(void*) + 232 6 libsystem_pthread.dylib 0x101ad34c0 _pthread_start + 104 7 libsystem_pthread.dylib 0x101ace6f0 thread_start + 8 Thread 3: 0 libsystem_pthread.dylib 0x101ace6dc start_wqthread + 0 Thread 4: 0 libsystem_pthread.dylib 0x101ace6dc start_wqthread + 0 Thread 5: 0 libsystem_pthread.dylib 0x101ace6dc start_wqthread + 0 Thread 6: 0 libsystem_pthread.dylib 0x101ace6dc start_wqthread + 0 Thread 7: 0 libsystem_pthread.dylib 0x101ace6dc start_wqthread + 0 Thread 8: 0 libsystem_pthread.dylib 0x101ace6dc start_wqthread + 0 Thread 9:: com.apple.uikit.eventfetch-thread 0 libsystem_kernel.dylib 0x100ba8c10 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x100bb9da4 mach_msg2_internal + 76 2 libsystem_kernel.dylib 0x100bb0e34 mach_msg_overwrite + 532 3 libsystem_kernel.dylib 0x100ba8f88 mach_msg + 20 4 CoreFoundation 0x1803eded8 __CFRunLoopServiceMachPort + 156 5 CoreFoundation 0x1803e85b8 __CFRunLoopRun + 1148 6 CoreFoundation 0x1803e7d28 CFRunLoopRunSpecific + 572 7 Foundation 0x180dd7a98 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208 8 Foundation 0x180dd7cbc -[NSRunLoop(NSRunLoop) runUntilDate:] + 60 9 UIKitCore 0x18535d304 -[UIEventFetcher threadMain] + 404 10 Foundation 0x180dfe27c __NSThread__start__ + 720 11 libsystem_pthread.dylib 0x101ad34c0 _pthread_start + 104 12 libsystem_pthread.dylib 0x101ace6f0 thread_start + 8 Thread 10: 0 libsystem_pthread.dylib 0x101ace6dc start_wqthread + 0 Thread 11: 0 libsystem_kernel.dylib 0x100bac110 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x101ad3a78 _pthread_cond_wait + 1216 2 shared 0x1052e75d4 (anonymous namespace)::waitInNativeState(_opaque_pthread_cond_t*, _opaque_pthread_mutex_t*) + 136 3 shared 0x1052e6388 Worker::processQueueElement(bool) + 744 4 shared 0x1052e5f2c (anonymous namespace)::workerRoutine(void*) + 220 5 libsystem_pthread.dylib 0x101ad34c0 _pthread_start + 104 6 libsystem_pthread.dylib 0x101ace6f0 thread_start + 8 Thread 12: 0 libsystem_kernel.dylib 0x100bac110 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x101ad3a78 _pthread_cond_wait + 1216 2 shared 0x1052e75d4 (anonymous namespace)::waitInNativeState(_opaque_pthread_cond_t*, _opaque_pthread_mutex_t*) + 136 3 shared 0x1052e6388 Worker::processQueueElement(bool) + 744 4 shared 0x1052e5f2c (anonymous namespace)::workerRoutine(void*) + 220 5 libsystem_pthread.dylib 0x101ad34c0 _pthread_start + 104 6 libsystem_pthread.dylib 0x101ace6f0 thread_start + 8 Thread 0 crashed with ARM Thread State (64-bit): x0: 0x000000016f2f75c0 x1: 0x0000000000000001 x2: 0x0000000000000033 x3: 0x0000000000000010 x4: 0x0000000000000000 x5: 0x000000016f2f6e98 x6: 0x0000000000000018 x7: 0x000000000000001f x8: 0x000000016f2f7900 x9: 0x0000000101c094c0 x10: 0x0000000104d40020 x11: 0x0000000104d40020 x12: 0x0000000104a40408 x13: 0x000000016f2f6cb0 x14: 0x0000000104a40408 x15: 0x000000016f2f6bd0 x16: 0x0000000000000010 x17: 0x0000600003000870 x18: 0x0000000000000000 x19: 0x0000000100f0a8c0 x20: 0x0000000000000000 x21: 0x00000000000000b4 x22: 0x00000000000000b2 x23: 0x0000000000000000 x24: 0x0000000000000000 x25: 0x0000000000000060 x26: 0x0000000000000000 x27: 0x0000000000000000 x28: 0x000000016f2fe7d0 fp: 0x000000016f2f7940 lr: 0x00000001050734a0 sp: 0x000000016f2f7890 pc: 0x00000001050734a4 cpsr: 0x20001000 far: 0x0000000106399f24 esr: 0xf2000001 (Breakpoint) brk 1 Binary Images: 0x100dc0000 - 0x100e53fff dyld (*) /usr/lib/dyld 0x101268000 - 0x101273fff libobjc-trampolines.dylib (*) <13823d40-f83a-3ddf-8c9c-4391bdc3d01f> /Volumes/VOLUME/*/libobjc-trampolines.dylib 0x104ef4000 - 0x106abbfff shared (1.0) <0998c454-784c-3657-90d7-db89ccfa2fa7> /Users/USER/Library/Developer/CoreSimulator/Devices/A2FE2CCC-44AF-4EFC-9646-3D0DC306E624/data/Containers/Bundle/Application/2D813892-654E-48A6-9F1D-31789E9343E3/My application.app/Frameworks/shared.framework/shared 0x100c24000 - 0x100c2bfff libsystem_platform.dylib (*) /usr/lib/system/libsystem_platform.dylib 0x100ba8000 - 0x100bdffff libsystem_kernel.dylib (*) <642a38ac-927b-39b2-9654-365bc3f3c14e> /usr/lib/system/libsystem_kernel.dylib 0x101acc000 - 0x101adbfff libsystem_pthread.dylib (*) /usr/lib/system/libsystem_pthread.dylib 0x101b08000 - 0x101b23fff com.apple.mlcompiler.services (95) /Volumes/VOLUME/*/MLCompilerServices.framework/MLCompilerServices 0x100afc000 - 0x100b03fff com.github.alexzhirkevich.lookandfeel (1.0) <99ad2b48-4edf-3a33-b19f-0258f8d6b865> /Users/USER/Library/Developer/CoreSimulator/Devices/A2FE2CCC-44AF-4EFC-9646-3D0DC306E624/data/Containers/Bundle/Application/2D813892-654E-48A6-9F1D-31789E9343E3/My application.app/My application 0x100c74000 - 0x100cbbfff dyld_sim (*) /Volumes/VOLUME/*/dyld_sim 0x184703000 - 0x18603ffff com.apple.UIKitCore (1.0) <6b64a343-f832-3b1d-a6c3-f8ed32b35a83> /Volumes/VOLUME/*/UIKitCore.framework/UIKitCore 0x189db5000 - 0x18a0a8fff com.apple.QuartzCore (1.11) <74469130-45f1-34bd-b386-da8c0072f37d> /Volumes/VOLUME/*/QuartzCore.framework/QuartzCore 0x180361000 - 0x180713fff com.apple.CoreFoundation (6.9) /Volumes/VOLUME/*/CoreFoundation.framework/CoreFoundation 0x18e7ca000 - 0x18e7d2fff com.apple.GraphicsServices (1.0) /Volumes/VOLUME/*/GraphicsServices.framework/GraphicsServices 0x1c3c80000 - 0x1c56dcfff com.apple.SwiftUI (5.0.83.1.105) /Volumes/VOLUME/*/SwiftUI.framework/SwiftUI 0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ??? 0x1802bd000 - 0x18033bfff libc++.1.dylib (*) <3858bbbd-d50a-32da-8b7a-69780769b396> /Volumes/VOLUME/*/libc++.1.dylib 0x180793000 - 0x181247fff com.apple.Foundation (6.9) <508eec71-652e-35bc-b02c-7dff66ccd20a> /Volumes/VOLUME/*/Foundation.framework/Foundation EOF ```
alexzhirkevich commented 1 year ago

Functions annotated with @composable are not allowed to have return values. This is a rule.

S u r e

igordmn commented 1 year ago

Isn't reproducible on desktop

Reproducer on iOS:

import androidx.compose.runtime.Composable

@Composable
fun App() {
    val a = test()
}

@Composable
fun test(): String? = null

Functions annotated with https://github.com/composable are not allowed to have return values. This is a rule.

There is no such rule, it is valid to return a value from Composable. But these kind of Composables have different semantics and different code style rules

alexzhirkevich commented 1 year ago

Functions annotated with https://github.com/composable are not allowed to have return values. This is a rule.

Btw, this was not my comment xD. Original one was deleted

findusl commented 12 months ago

I ran into the same issue. Very unexpected.

I noticed, it doesn't seem deterministic. I have two code paths that lead to the Composable Function that triggers the iOS crash.

  • One just passes { null } and crashes.
  • The other has a series of if-else and only sometimes returns null, but doesn't cause a crash even when it returns null.
eymar commented 12 months ago

The fix is on its way. The workaround for now:

@Composable
fun test() : Int? {
   val res: Int? = null
   return res
}
eymar commented 11 months ago

We've released org.jetbrains.compose.compiler:compiler:1.5.4. It contains a fix. It requires kotlin 1.9.21.

compose {
    kotlinCompilerPlugin.set("1.5.4")
}

https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compatibility-and-versioning.html#use-a-developer-version-of-compose-multiplatform-compiler


By default this compiler plugin will be applied for projects with kotlin 1.9.21 in the future build 1.5.11

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.