-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwareparameter packsFeature → generics: Parameter packsFeature → generics: Parameter packs
Description
Description
Some remarks on the program below:
- this compiles without issues for both debug and release builds
- it crashes at runtime, with a BAD_ACCESS in the
isEmptyvariable access inhmmm, for both debug and release builds - changing
isEmptyfrom a computed property into e.g.let isEmpty = truewill also result in a runtime crash, albeit with a different stack trace (see below) - removing the
breakstatement from thefor _ in repeat eachloop in the initialiser makes everything work fine - removing the
breakstatement from the for loop inhmmmstill causes it to crash, but at a different place and with a different backtrace - turning
Entryinto a struct makes everything work fine.
Reproduction
final class Entry<Results> {
var isEmpty: Bool { true }
}
struct Foo<each Results> {
private let entry: (repeat Entry<each Results>)
init(_ entry: (repeat Entry<each Results>)) {
self.entry = entry
for entry in repeat each entry {
if entry.isEmpty {
break
}
}
}
var hmmm: Void {
for entry in repeat each entry {
if !entry.isEmpty { // <-- EXC_BAD_ACCESS
break
}
}
}
}
_ = Foo((
Entry<Any>()
)).hmmmStack dump
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xbca019aec150)
frame #0: 0x00000001000017cc test_2025-01-12`Entry.isEmpty.getter() at <stdin>:0
* frame #1: 0x0000000100001704 test_2025-01-12`Foo.hmmm.getter() at main.swift:54:23
frame #2: 0x0000000100000ce8 test_2025-01-12`main at main.swift:65:4
frame #3: 0x00000001913df154 dyld`start + 2476
Expected behavior
I see no reason why this should not work.
Environment
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx14.0
Additional information
This is the backtrace of the crash of the alternative version (when isEmpty is let isEmpty = true):
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x44b5779b4ff0)
frame #0: 0x00000001a17ea188 libswiftCore.dylib`_swift_release_dealloc + 32
frame #1: 0x00000001a17eacf8 libswiftCore.dylib`bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 136
frame #2: 0x0000000100002c78 test_2025-01-12`outlined destroy of Foo<Pack{Any}> at <compiler-generated>:0
* frame #3: 0x0000000100002384 test_2025-01-12`main at main.swift:39:4
frame #4: 0x00000001913df154 dyld`start + 2476
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwareparameter packsFeature → generics: Parameter packsFeature → generics: Parameter packs