diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -343,7 +343,7 @@ def _buildregexmatch(kindpats, globsuffi
             raise
         regexa, a = _buildregexmatch(kindpats[:l//2], globsuffix)
         regexb, b = _buildregexmatch(kindpats[l//2:], globsuffix)
-        return pat, lambda s: a(s) or b(s)
+        return regex, lambda s: a(s) or b(s)
     except re.error:
         for k, p in kindpats:
             try:
diff --git a/tests/test-walk.t b/tests/test-walk.t
--- a/tests/test-walk.t
+++ b/tests/test-walk.t
@@ -331,3 +331,14 @@ Test listfile and listfile0
   f  mammals/skunk  mammals/skunk  exact
 
   $ cd ..
+
+Test split patterns on overflow
+
+  $ cd t
+  $ echo fennel > overflow.list
+  $ python -c "for i in xrange(20000 / 100): print 'x' * 100" >> overflow.list
+  $ echo fenugreek >> overflow.list
+  $ hg debugwalk 'listfile:overflow.list' 2>&1 | grep -v '^xxx'
+  f  fennel     fennel     exact
+  f  fenugreek  fenugreek  exact
+  $ cd ..