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]