@@ -676,12 +676,14 @@ where
676676 let ( term, sort) = formula_or_term
677677 . into_term ( )
678678 . ok_or_else ( || ParseAttrError :: unexpected_formula ( "before projection" ) ) ?;
679- let sort = fields. iter ( ) . fold ( sort, |acc, field| match ( acc, field) {
680- ( acc, Field :: Index ( idx) ) => acc. tuple_elem ( * idx) ,
681- ( acc, Field :: Store ( _, _) ) => acc,
682- ( chc:: Sort :: Array ( _, elem) , Field :: Select ( _) ) => * elem,
683- _ => panic ! ( "invalid field access" ) ,
684- } ) ;
679+ let sort = fields
680+ . iter ( )
681+ . try_fold ( sort, |acc, field| match ( acc, field) {
682+ ( acc, Field :: Index ( idx) ) => Ok ( acc. tuple_elem ( * idx) ) ,
683+ ( acc, Field :: Store ( _, _) ) => Ok ( acc) ,
684+ ( chc:: Sort :: Array ( _, elem) , Field :: Select ( _) ) => Ok ( * elem) ,
685+ ( acc, _) => Err ( ParseAttrError :: unsorted_op ( "select" , acc. clone ( ) ) ) ,
686+ } ) ?;
685687 let term = fields. into_iter ( ) . fold ( term, |acc, field| match field {
686688 Field :: Index ( idx) => acc. tuple_proj ( idx) ,
687689 Field :: Store ( idx, val) => acc. store ( idx, val) ,
0 commit comments