11
$\begingroup$

Bug introduced in 10.1 and fixed in 10.2.0


In v10.1.0.0 on Linux, when Blank[] is used in Alternatives with pattern that can match a sequence, whole pattern unexpectedly matches sequences of any length.

ClearAll[matchLists]
matchLists[patt_] :=
    MatchQ[#, patt] & /@ {{}, {1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}}

matchLists[{_ | PatternSequence[]}]
(*{True, True, True, True, True}*)
matchLists[{_ | PatternSequence[_, _, _]}]
(*{True, True, True, True, True}*)
matchLists[{_ | __}]
(*{True, True, True, True, True}*)
matchLists[{_ | Repeated[_, {2, 3}]}]
(*{True, True, True, True, True}*)

If Blank is non-empty, or is inside Pattern, everything works as expected:

matchLists[{x_ | PatternSequence[]}]
(*{True, True, False, False, False}*)
matchLists[{_Integer | PatternSequence[_, _, _]}]
(*{False, True, False, True, False}*)
matchLists[{y_ | __}]
(*{False, True, True, True, True}*)
matchLists[{_Integer | Repeated[_, {2, 3}]}]
(*{False, True, True, True, False}*)

In all previous versions I have available: 8.0.0, 9.0.1 and 10.0.2, all above patterns work as expected:

matchLists[{_ | PatternSequence[]}]
(*{True, True, False, False, False}*)
matchLists[{_ | PatternSequence[_, _, _]}]
(*{False, True, False, True, False}*)
matchLists[{_ | __}]
(*{False, True, True, True, True}*)
matchLists[{_ | Repeated[_, {2, 3}]}]
(*{False, True, True, True, False}*)

matchLists[{x_ | PatternSequence[]}]
(*{True, True, False, False, False}*)
matchLists[{_Integer | PatternSequence[_, _, _]}]
(*{False, True, False, True, False}*)
matchLists[{y_ | __}]
(*{False, True, True, True, True}*)
matchLists[{_Integer | Repeated[_, {2, 3}]}]
(*{False, True, True, True, False}*)

Can someone confirm this behavior?


Reported to WRI as [CASE:3059582]

$\endgroup$
5
  • 3
    $\begingroup$ Confirmed on 10.0 (linux, mma online), 10.1(windows 8.1 ,with string pattern fix), 10.1(OS X 10.10.3), 9.0.1 (windows xp), 8.0.4 (windows xp), $\endgroup$
    – vapor
    Apr 16, 2015 at 17:14
  • 1
    $\begingroup$ @Felix thanks. To be clear, you confirm buggy behavior in 10.1 and expected behavior in other versions? $\endgroup$
    – jkuczm
    Apr 16, 2015 at 17:27
  • 1
    $\begingroup$ Yes, I got exactly the same results as you did. $\endgroup$
    – vapor
    Apr 16, 2015 at 17:30
  • $\begingroup$ @Felix OK, thanks again. $\endgroup$
    – jkuczm
    Apr 16, 2015 at 17:31
  • 3
    $\begingroup$ This has been fixed in our latest development builds. Thanks for reporting it!! $\endgroup$
    – Stefan R
    May 7, 2015 at 16:46

1 Answer 1

8
$\begingroup$

This bug has been fixed in version 10.2.

$Version
(* "10.2.0 for Linux x86 (64-bit) (July 6, 2015)" *)

matchLists[patt_] := 
    MatchQ[#, patt] & /@ {{}, {1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}}

matchLists[{_ | PatternSequence[]}]
matchLists[{x_ | PatternSequence[]}]
(* {True, True, False, False, False} *)
(* {True, True, False, False, False} *)

matchLists[{_ | PatternSequence[_, _, _]}]
matchLists[{_Integer | PatternSequence[_, _, _]}]
(* {False, True, False, True, False} *)
(* {False, True, False, True, False} *)

matchLists[{_ | __}]
matchLists[{y_ | __}]
(* {False, True, True, True, True} *)
(* {False, True, True, True, True} *)

matchLists[{_ | Repeated[_, {2, 3}]}]
matchLists[{_Integer | Repeated[_, {2, 3}]}]
(* {False, True, True, True, False} *)
(* {False, True, True, True, False} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.