summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ocaml_backend.ml2
-rw-r--r--test/ocaml/string_of_struct/expect0
-rw-r--r--test/ocaml/string_of_struct/sos.sail17
-rw-r--r--test/ocaml/string_of_struct/test.isail4
4 files changed, 22 insertions, 1 deletions
diff --git a/src/ocaml_backend.ml b/src/ocaml_backend.ml
index 96dfd9d3..c535554b 100644
--- a/src/ocaml_backend.ml
+++ b/src/ocaml_backend.ml
@@ -528,7 +528,7 @@ let ocaml_string_of_enum ctx id ids =
let ocaml_string_of_struct ctx id typq fields =
let arg = gensym () in
let ocaml_field (typ, id) =
- separate space [string (string_of_id id ^ " = \""); string "^"; ocaml_string_typ typ arg ^^ string "." ^^ zencode ctx id]
+ separate space [string (string_of_id id ^ " = \""); string "^"; ocaml_string_typ typ (arg ^^ string "." ^^ zencode ctx id)]
in
separate space [string "let"; ocaml_string_of id; parens (arg ^^ space ^^ colon ^^ space ^^ zencode ctx id); equals]
^//^ (string "\"{" ^^ separate_map (hardline ^^ string "^ \", ") ocaml_field fields ^^ string " ^ \"}\"")
diff --git a/test/ocaml/string_of_struct/expect b/test/ocaml/string_of_struct/expect
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/ocaml/string_of_struct/expect
diff --git a/test/ocaml/string_of_struct/sos.sail b/test/ocaml/string_of_struct/sos.sail
new file mode 100644
index 00000000..6d14dfd7
--- /dev/null
+++ b/test/ocaml/string_of_struct/sos.sail
@@ -0,0 +1,17 @@
+/* This is a regression test for a bug where an option type in a
+struct would cause the ocaml backend to generate a bad string_of
+function for the struct */
+
+union option ('a : Type) = {
+ None,
+ Some : 'a
+}
+
+struct test = {
+ test1 : int,
+ test2 : option(int)
+}
+
+val main : unit -> unit
+
+function main () = () \ No newline at end of file
diff --git a/test/ocaml/string_of_struct/test.isail b/test/ocaml/string_of_struct/test.isail
new file mode 100644
index 00000000..6a9595e3
--- /dev/null
+++ b/test/ocaml/string_of_struct/test.isail
@@ -0,0 +1,4 @@
+:output result
+main()
+:run
+:quit \ No newline at end of file