Array element inclusion test compiles but crashes with EXC_BAD_ACCESS

import Foundation

[String.self].contains(where: { $0 == String.self })

swift-driver version: 1.127.14.1 Apple Swift version 6.2.1 (swiftlang-6.2.1.4.8 clang-1700.4.4.1)

Xcode 26.1

Call stack:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  frame #0: 0x0000000197214f74 libswiftCore.dylib`swift_isClassType
  frame #1: 0x00000001972ff770 libswiftCore.dylib`getContiguousArrayStorageType(for:) + 24
  frame #2: 0x00000001972ff6d0 libswiftCore.dylib`_allocateUninitializedArray(_:) + 40
  frame #3: 0x0000000100754338 $__lldb_expr10`main at MyPlayground.playground:3:1
  frame #4: 0x00000001004a5d00 MyPlayground`linkResources + 264
  frame #5: 0x0000000180456170 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
  frame #6: 0x00000001804558f8 CoreFoundation`__CFRunLoopDoBlocks + 340
  frame #7: 0x0000000180454c68 CoreFoundation`__CFRunLoopRun + 788
  frame #8: 0x000000018044fcec CoreFoundation`_CFRunLoopRunSpecificWithOptions + 496
  frame #9: 0x00000001926be9bc GraphicsServices`GSEventRunModal + 116
  frame #10: 0x000000018630f0d8 UIKitCore`-[UIApplication _run] + 772
  frame #11: 0x0000000186313300 UIKitCore`UIApplicationMain + 124
* frame #12: 0x00000001004a5e70 MyPlayground`main + 368
  frame #13: 0x000000010055d3d0 dyld_sim`start_sim + 20
  frame #14: 0x000000010082cd54 dyld`start + 7184
1 Like

Neither import Foundation nor the playground is necessary, it crashes in isolation when AOT-compiled too:

StringSelfContains.swift:

[String.self].contains(where: { $0 == String.self })
swiftc -swift-version 6 StringSelfContains.swift && lldb ./StringSelfContains
<various output>
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000199a74ca8 libswiftCore.dylib`swift_isClassType
    frame #1: 0x0000000199712e90 libswiftCore.dylib`getContiguousArrayStorageType(for:) + 68
    frame #2: 0x0000000199712da8 libswiftCore.dylib`_allocateUninitializedArray(_:) + 40
    frame #3: 0x00000001000007d0 StringSelfContains`main + 80
    frame #4: 0x0000000187b7eb98 dyld`start + 6076

seems it works on main and the 6.3 dev branch, and also worked in earlier compilers, so maybe something specific to 6.2 that's already been fixed? may be little solace, but could maybe work around the issue by wrapping the metatypes in ObjectIdentifier.

3 Likes

+1 Tested in Godbolt on 6.2 and 5.5 couldn’t reproduce.

Thanks for the relieving response about 6.3 version. No worries, I didn’t need that code anyways :)

1 Like