@@ -63,7 +63,7 @@ public final class IncrementalParseTransition {
6363 reusedNodeDelegate: IncrementalParseReusedNodeDelegate ? = nil ) {
6464 self . init (
6565 previousTree: previousTree,
66- edits: ConcurrentEdits ( concurrent: edits) ,
66+ edits: try ! ConcurrentEdits ( concurrent: edits) ,
6767 reusedNodeDelegate: reusedNodeDelegate
6868 )
6969 }
@@ -101,14 +101,27 @@ fileprivate extension Sequence where Element: Comparable {
101101/// 1. not be overlapping.
102102/// 2. be in increasing source offset order.
103103public 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+
104115 /// The raw concurrent edits. Are guaranteed to satisfy the requirements
105116 /// stated above.
106117 public let edits : [ SourceEdit ]
107118
108119 /// Initialize this struct from edits that are already in a concurrent form
109120 /// 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+ }
112125 self . edits = concurrent
113126 }
114127
@@ -122,14 +135,22 @@ public struct ConcurrentEdits {
122135 /// to '012345' results in 'xyz012345'.
123136
124137 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+ }
126143 }
127144
128145 /// Construct a concurrent edits struct from a single edit. For a single edit,
129146 /// there is no differentiation between being it being applied concurrently
130147 /// or sequentially.
131148 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+ }
133154 }
134155
135156 private static func translateSequentialEditsToConcurrentEdits(
0 commit comments