I get the following error when running swift run inside of an executable Swift Package:
zsh: segmentation fault swift run
I have been able to boil the code down to the following:
enum MyEnum {
case FirstCase
case SecondCase
case Other
}
struct MyEnumCollection {
private var enums: [MyEnum]
}
extension MyEnumCollection: RangeReplaceableCollection {
public init() {
self.enums = []
}
}
extension MyEnumCollection: Collection {
public var startIndex: Int {
0
}
public var endIndex: Int {
self.enums.count
}
public subscript(position: Int) -> MyEnum {
return self.enums[position]
}
public func index(after i: Int) -> Int {
return self.enums.index(after: i)
}
}
var collection = MyEnumCollection()
collection.append(MyEnum.FirstCase)
The segmentation fault happens on the last line, at the append statement.
Can someone help me understand why this is happening and how I should fix this?