@@ -190,7 +190,7 @@ public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflect
190190
191191 /// Pops \p numBits from the path.
192192 private func pop( numBits: Int ) -> SmallProjectionPath {
193- return Self ( bytes: bytes & >> numBits)
193+ return Self ( bytes: bytes >> numBits)
194194 }
195195
196196 /// Pops and returns the first path component included the resulting path
@@ -214,7 +214,7 @@ public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflect
214214 // Ignore zero indices
215215 return self
216216 }
217- if k == . indexedElement {
217+ if k == . indexedElement && index &+ i >= 0 {
218218 // "Merge" two constant successive indexed elements
219219 return pop ( numBits: numBits) . push ( . indexedElement, index: index + i)
220220 }
@@ -691,7 +691,8 @@ extension SmallProjectionPath {
691691 overlapping ( )
692692 predicates ( )
693693 path2path ( )
694-
694+ indexedElements ( )
695+
695696 func basicPushPop( ) {
696697 let p1 = SmallProjectionPath ( . structField, index: 3 )
697698 . push ( . classField, index: 12345678 )
@@ -964,5 +965,23 @@ extension SmallProjectionPath {
964965 assert ( result == nil )
965966 }
966967 }
968+
969+ func indexedElements( ) {
970+ let p1 = SmallProjectionPath ( . indexedElement, index: 1 )
971+ let ( k1, i1, s1) = p1. pop ( )
972+ assert ( k1 == . indexedElement && i1 == 1 && s1. isEmpty)
973+
974+ let p2 = SmallProjectionPath ( . indexedElement, index: - 1 )
975+ let ( k2, _, s2) = p2. pop ( )
976+ assert ( k2 == . anything && s2. isEmpty)
977+
978+ let p3 = SmallProjectionPath ( . indexedElement, index: 0xfffffffffffff )
979+ let ( k3, i3, s3) = p3. pop ( )
980+ assert ( k3 == . indexedElement && i3 == 0xfffffffffffff && s3. isEmpty)
981+
982+ let p4 = p3. push ( . indexedElement, index: Int . max)
983+ let ( k4, _, s4) = p4. pop ( )
984+ assert ( k4 == . anyIndexedElement && s4. isEmpty)
985+ }
967986 }
968987}
0 commit comments