nickva commented on code in PR #5858:
URL: https://github.com/apache/couchdb/pull/5858#discussion_r3392273919


##########
src/mango/src/mango_selector.erl:
##########
@@ -427,15 +494,31 @@ match({[{<<"$elemMatch">>, Arg}]}, Values, Cmp) when 
is_list(Values) ->
         _:_ ->
             false
     end;
-match({[{<<"$elemMatch">>, _Arg}]}, _Value, _Cmp) ->
+match({[{<<"$elemMatch">>, _Arg}]}, _Value, #ctx{verbose = false}) ->
     false;
+match({[{<<"$elemMatch">>, _Arg}]}, [], #ctx{negate = false} = Ctx) ->
+    [#failure{op = elemMatch, type = empty_list, ctx = Ctx}];
+match({[{<<"$elemMatch">>, _Arg}]}, [], #ctx{negate = true}) ->
+    [];
+match({[{<<"$elemMatch">>, Arg}]}, Values, #ctx{negate = true} = Ctx) ->

Review Comment:
   I think we lost a `is_list(Values)` guard? We should try to have a test 
where $elemMatch with/without negate and with verbose=true would blow up on 
lists:enumerate/2
   
   
   ```
   5> lists:enumerate(0, 42).
   * exception error: no function clause matching lists:enumerate_1(0,1,42) 
(lists.erl:1856)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to