In my project that uses the swift-binary-parsing package, I get three intermittent lifetime-related compile errors in one source file; “intermittent” in the sense that, if I build again (with no changes!) they go away for a while, then reappear a few hours later. As far as I can tell the errors are bogus.
Just upgraded to Swift 6.3 (Xcode 26.3 to 26.4) and it’s still happening, so I want to ask if there’s any known cause for this or whether I should file a bug report on swiftc.
The three errors are nearly identical, on different methods in the source file, and look like:
Container.swift:192:21: error: lifetime-dependent value escapes its scope
return data.bytes.unsafeLoadUnaligned(fromByteOffset: Int(offset), as: UInt16.self).byteSwapped
^
Container.swift:46:16: note: it depends on the lifetime of variable 'data'
public let data: Data
^
Container.swift:192:27: note: this use of the lifetime-dependent value is out of scope
return data.bytes.unsafeLoadUnaligned(fromByteOffset: Int(offset), as: UInt16.self).byteSwapped
^
A highly abbreviated listing of the source:
import Foundation
import BinaryParsing
public final class Container : Sendable {
public let data: Data // line 46
func getUInt16BE(_ offset: Offset) -> UInt16 {
precondition(offset + 2 <= data.count)
return data.bytes.unsafeLoadUnaligned(fromByteOffset: Int(offset), as: UInt16.self).byteSwapped // line 192
}
...
}
The target has .enableExperimentalFeature("Lifetimes").
Is this worth a compiler bug report?