EXC_BREAKPOINT when creating array with specific types

I'm not new to Swift, but I've run into an odd crash that I'd be grateful for any explanation as to why it occurs (I've already worked around this).

I'm trying to create an array of WrappingStruct's. This struct contains two properties, an SingleValueEnum and a Date. This causes an EXC_BREAKPOINT crash when run in the debugger.

This crash seems to be closely tied to the types I'm using and the exact structure I've created. I can resolve this by any of the below
a.) Adding a second case to the enum
b.) Changing the associated value from TimeZone to String
c.) Adding a third property to the struct
d.) Removing the enum property from the struct

Any insight as to why this causes the crash would be greatly appreciated.

import UIKit

enum SingleValueEnum: Hashable {
    case timezone(TimeZone)
//    case secondary(TimeZone)
}

/* WORKING EXAMPLES */
struct WrappingStruct_Works {
    let enumValue: SingleValueEnum
}

/* FAILING EXAMPLES */
struct WrappingStruct_Fails {
    let enumValue: SingleValueEnum
    let date = Date()
//    let otherProperty = "Hey There"
}

class ViewController: UIViewController {

    let works = [WrappingStruct_Works]()
    let fails = [WrappingStruct_Fails]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // should print out 'works: []' as its an empty, but initialized array
        print("works: \(works)")
        
        // should print out 'fails: []' as its an empty, but initialized array
        // but it causes an EXC_BREAKPOINT
        print("fails: \(fails)")
    }
}

Stack Trace
It crashes at site 7 with Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000107974d95 BugTest`___lldb_unnamed_symbol4$$BugTest + 197
    frame #1: 0x0000000108e630f7 libswiftCore.dylib`swift::storeEnumTagSinglePayloadImpl(swift::OpaqueValue*, unsigned int, unsigned int, swift::TargetMetadata<swift::InProcess> const*, unsigned long, unsigned int, void (swift::OpaqueValue*, unsigned int, unsigned int, swift::TargetMetadata<swift::InProcess> const*) swiftcall*) + 135
    frame #2: 0x0000000108e63060 libswiftCore.dylib`swift_storeEnumTagSinglePayloadGeneric + 32
    frame #3: 0x0000000107974cc0 BugTest`storeEnumTagSinglePayload for WrappingStruct_Fails at <compiler-generated>:0
    frame #4: 0x0000000108bb2546 libswiftCore.dylib`Swift.Array.description.getter : Swift.String + 518
  * frame #5: 0x0000000108bb3034 libswiftCore.dylib`protocol witness for Swift.CustomStringConvertible.description.getter : Swift.String in conformance Swift.Array<A> : Swift.CustomStringConvertible in Swift + 20
    frame #6: 0x0000000108bd2eaa libswiftCore.dylib`Swift.DefaultStringInterpolation.appendInterpolation<A where A: Swift.CustomStringConvertible>(A) -> () + 26
    frame #7: 0x00000001079734c0 BugTest`ViewController.viewDidLoad(self=0x00007fdd62d16af0) at ViewController.swift:33:24
    frame #8: 0x0000000107973894 BugTest`@objc ViewController.viewDidLoad() at <compiler-generated>:0
    frame #9: 0x000000010c00c43b UIKitCore`-[UIViewController loadViewIfRequired] + 1183
    frame #10: 0x000000010c00c868 UIKitCore`-[UIViewController view] + 27
    frame #11: 0x000000010c644c33 UIKitCore`-[UIWindow addRootViewControllerViewIfPossible] + 122
    frame #12: 0x000000010c645327 UIKitCore`-[UIWindow _setHidden:forced:] + 289
    frame #13: 0x000000010c657f86 UIKitCore`-[UIWindow makeKeyAndVisible] + 42
    frame #14: 0x000000010c607f1c UIKitCore`-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4555
    frame #15: 0x000000010c60d0c6 UIKitCore`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1617
    frame #16: 0x000000010be526d6 UIKitCore`__111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 904
    frame #17: 0x000000010be5afce UIKitCore`+[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
    frame #18: 0x000000010be522ec UIKitCore`-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
    frame #19: 0x000000010be52c48 UIKitCore`-[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1091
    frame #20: 0x000000010be50fba UIKitCore`__82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 782
    frame #21: 0x000000010be50c71 UIKitCore`-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
    frame #22: 0x000000010be559b6 UIKitCore`__125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 576
    frame #23: 0x000000010be56610 UIKitCore`_performActionsWithDelayForTransitionContext + 100
    frame #24: 0x000000010be5571d UIKitCore`-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
    frame #25: 0x000000010be5a6d0 UIKitCore`-[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
    frame #26: 0x000000010c60b9a8 UIKitCore`-[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 514
    frame #27: 0x000000010c1c2dfa UIKitCore`-[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    frame #28: 0x0000000114e2f125 FrontBoardServices`-[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448
    frame #29: 0x0000000114e38ed6 FrontBoardServices`__56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 283
    frame #30: 0x0000000114e38700 FrontBoardServices`__40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53
    frame #31: 0x000000010b030db5 libdispatch.dylib`_dispatch_client_callout + 8
    frame #32: 0x000000010b0342ba libdispatch.dylib`_dispatch_block_invoke_direct + 300
    frame #33: 0x0000000114e6a146 FrontBoardServices`__FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    frame #34: 0x0000000114e69dfe FrontBoardServices`-[FBSSerialQueue _performNext] + 451
    frame #35: 0x0000000114e6a393 FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 42
    frame #36: 0x0000000109c04be1 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #37: 0x0000000109c04463 CoreFoundation`__CFRunLoopDoSources0 + 243
    frame #38: 0x0000000109bfeb1f CoreFoundation`__CFRunLoopRun + 1231
    frame #39: 0x0000000109bfe302 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #40: 0x0000000111d832fe GraphicsServices`GSEventRunModal + 65
    frame #41: 0x000000010c60eba2 UIKitCore`UIApplicationMain + 140
    frame #42: 0x000000010797588b BugTest`main at AppDelegate.swift:12:7
    frame #43: 0x000000010b0a5541 libdyld.dylib`start + 1

A crash report would also be useful.

I just added a stack trace.

I’m going to go out on a limb here and suggest that you file a bug about this. I distilled your code down to a simple command-line tool that still crashes:

import Foundation

enum SingleValueEnum {
    case timezone(TimeZone)
}

struct WrappingStruct_Fails {
    let enumValue: SingleValueEnum
    let date: Date
}

func main() {
    let fails = [WrappingStruct_Fails]()
    print("fails: \(fails)")
}

main()

I can’t see any obvious problems with this code, hence my recommendation.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

Thanks Quinn!

I assumed, I just wanted to make sure I wasn't missing something.

I've created a bug: https://bugs.swift.org/browse/SR-10626

Terms of Service

Privacy Policy

Cookie Policy