@@ -63,7 +63,7 @@ public final class IncrementalParseTransition {
63
63
reusedNodeDelegate: IncrementalParseReusedNodeDelegate ? = nil ) {
64
64
self . init (
65
65
previousTree: previousTree,
66
- edits: ConcurrentEdits ( concurrent: edits) ,
66
+ edits: try ! ConcurrentEdits ( concurrent: edits) ,
67
67
reusedNodeDelegate: reusedNodeDelegate
68
68
)
69
69
}
@@ -101,14 +101,27 @@ fileprivate extension Sequence where Element: Comparable {
101
101
/// 1. not be overlapping.
102
102
/// 2. be in increasing source offset order.
103
103
public struct ConcurrentEdits {
104
+ enum ConcurrentEditsError : Error , CustomStringConvertible {
105
+ case editsNotConcurrent
106
+
107
+ var description : String {
108
+ switch self {
109
+ case . editsNotConcurrent:
110
+ return " Edits passed to ConcurrentEdits(concurrent:) does not satisfy the requirements posed by ConcurrentEdits "
111
+ }
112
+ }
113
+ }
114
+
104
115
/// The raw concurrent edits. Are guaranteed to satisfy the requirements
105
116
/// stated above.
106
117
public let edits : [ SourceEdit ]
107
118
108
119
/// Initialize this struct from edits that are already in a concurrent form
109
120
/// and are guaranteed to satisfy the requirements posed above.
110
- public init ( concurrent: [ SourceEdit ] ) {
111
- precondition ( Self . isValidConcurrentEditArray ( concurrent) )
121
+ public init ( concurrent: [ SourceEdit ] ) throws {
122
+ if !Self. isValidConcurrentEditArray ( concurrent) {
123
+ throw ConcurrentEditsError . editsNotConcurrent
124
+ }
112
125
self . edits = concurrent
113
126
}
114
127
@@ -122,14 +135,22 @@ public struct ConcurrentEdits {
122
135
/// to '012345' results in 'xyz012345'.
123
136
124
137
public init ( fromSequential sequentialEdits: [ SourceEdit ] ) {
125
- self . init ( concurrent: Self . translateSequentialEditsToConcurrentEdits ( sequentialEdits) )
138
+ do {
139
+ try self . init ( concurrent: Self . translateSequentialEditsToConcurrentEdits ( sequentialEdits) )
140
+ } catch {
141
+ fatalError ( " ConcurrentEdits created by translateSequentialEditsToConcurrentEdits do not satisfy ConcurrentEdits requirements " )
142
+ }
126
143
}
127
144
128
145
/// Construct a concurrent edits struct from a single edit. For a single edit,
129
146
/// there is no differentiation between being it being applied concurrently
130
147
/// or sequentially.
131
148
public init ( _ single: SourceEdit ) {
132
- self . init ( concurrent: [ single] )
149
+ do {
150
+ try self . init ( concurrent: [ single] )
151
+ } catch {
152
+ fatalError ( " A single edit doesn't satisfy the ConcurrentEdits requirements? " )
153
+ }
133
154
}
134
155
135
156
private static func translateSequentialEditsToConcurrentEdits(
0 commit comments