@@ -190,7 +190,7 @@ public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflect
190
190
191
191
/// Pops \p numBits from the path.
192
192
private func pop( numBits: Int ) -> SmallProjectionPath {
193
- return Self ( bytes: bytes & >> numBits)
193
+ return Self ( bytes: bytes >> numBits)
194
194
}
195
195
196
196
/// Pops and returns the first path component included the resulting path
@@ -214,7 +214,7 @@ public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflect
214
214
// Ignore zero indices
215
215
return self
216
216
}
217
- if k == . indexedElement {
217
+ if k == . indexedElement && index &+ i >= 0 {
218
218
// "Merge" two constant successive indexed elements
219
219
return pop ( numBits: numBits) . push ( . indexedElement, index: index + i)
220
220
}
@@ -691,7 +691,8 @@ extension SmallProjectionPath {
691
691
overlapping ( )
692
692
predicates ( )
693
693
path2path ( )
694
-
694
+ indexedElements ( )
695
+
695
696
func basicPushPop( ) {
696
697
let p1 = SmallProjectionPath ( . structField, index: 3 )
697
698
. push ( . classField, index: 12345678 )
@@ -964,5 +965,23 @@ extension SmallProjectionPath {
964
965
assert ( result == nil )
965
966
}
966
967
}
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
+ }
967
986
}
968
987
}
0 commit comments