mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
50 lines
1008 B
Swift
50 lines
1008 B
Swift
// RUN: %target-swift-frontend %s -emit-ir
|
|
|
|
// https://github.com/apple/swift/issues/43915
|
|
|
|
enum SampleType: UInt8 {
|
|
case Value = 1
|
|
case Array
|
|
case Dictionary
|
|
}
|
|
|
|
protocol ByteConvertible {
|
|
init?(bytes: [UInt8], startOffset: Int)
|
|
func rawBytes() -> [UInt8]
|
|
func bytesNeeded() -> Int
|
|
}
|
|
|
|
protocol TypeRequestable {
|
|
static func containerType() -> SampleType
|
|
}
|
|
|
|
struct Sample<T, C> where T: ByteConvertible, C: TypeRequestable {
|
|
let numberOfRecords: UInt32
|
|
let sizeInBytes: UInt64
|
|
var records: [T] = [] // problem line
|
|
|
|
init(records: [T]) {
|
|
numberOfRecords = 0
|
|
sizeInBytes = 0
|
|
|
|
self.records.reserveCapacity(records.count)
|
|
self.records += records
|
|
}
|
|
}
|
|
|
|
extension Sample: ByteConvertible {
|
|
init?(bytes: [UInt8], startOffset: Int = 0) {
|
|
numberOfRecords = 0
|
|
sizeInBytes = 0
|
|
records = []
|
|
}
|
|
|
|
func rawBytes() -> [UInt8] {
|
|
return []
|
|
}
|
|
|
|
func bytesNeeded() -> Int {
|
|
return 0
|
|
}
|
|
}
|