-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
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 softwaretriage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
The following code compiles successfully but crashes at runtime. The value.array is unexpectedly <uninitialized>.
Reproduction
@resultBuilder
struct StringArrayBuilder {
static func buildBlock(_ elements: String...) -> [String] {
elements
}
}
struct MyValue {
@StringArrayBuilder let array: [String]
}
let value = MyValue(array: {
"foo"
"bar"
})
print("Value?")
print(value.array.count) // Crashes because value.array is uninitializedStack dump
#0 0x00000001959fd178 in swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::incrementSlow ()
#1 (access of value.array)
Expected behavior
It should not crash, and the array should be initialized to ["foo", "bar"]. This works correctly if you change @StringArrayBuilder let array: [String] to @StringArrayBuilder let array: () -> [String], but that changes the semantics of the type.
Environment
Swift version 6.2.3 (swift-6.2.3-RELEASE)
Additional information
No response
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 softwaretriage neededThis issue needs more specific labelsThis issue needs more specific labels