In a '{...} as foo' binding, save the original bitstring offset and
authorRichard W.M. Jones <rich@annexia.org>
Tue, 17 Jan 2012 13:02:18 +0000 (13:02 +0000)
committerRichard W.M. Jones <rich@annexia.org>
Tue, 17 Jan 2012 13:02:18 +0000 (13:02 +0000)
length as 'foo'.  Before we were saving the running offset and length.
This commit also adds a regression test.  (Bug found by Matej Kosik).

pa_bitstring.ml
tests/test_90_bind_as.ml [new file with mode: 0644]

index 1414612..58fe1ed 100644 (file)
@@ -989,7 +989,8 @@ let output_bitmatch _loc bs cases =
        match bind with
        | Some name ->
            <:expr<
-             let $lid:name$ = ($lid:data$, $lid:off$, $lid:len$) in
+             let $lid:name$ = ($lid:data$,
+                                $lid:original_off$, $lid:original_len$) in
              $inner$
              >>
        | None -> inner in
diff --git a/tests/test_90_bind_as.ml b/tests/test_90_bind_as.ml
new file mode 100644 (file)
index 0000000..a83d7ce
--- /dev/null
@@ -0,0 +1,18 @@
+(* Regression test for bug in 'as-binding' found by Matej Kosik.
+ * $Id$
+ *)
+
+open Printf
+open Bitstring
+
+let bits = Bitstring.ones_bitstring 1 in
+bitmatch bits with
+| { _ : 1 } as foo ->
+  let len = Bitstring.bitstring_length foo in
+  if len <> 1 then (
+    hexdump_bitstring stderr foo;
+    eprintf "test error: length = %d, expecting 1\n" len;
+    exit 1
+  )
+| { _ } ->
+  assert false