From 4d8a4078990a00ffdc018bc8f5d4d5e3dcf6527d Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Tue, 18 Dec 2018 19:45:02 +0000 Subject: Experiment with generating type variable names in a repeatable way This results in much better error messages, as we can pick readable names that make sense, and should hopefully make the re-writer more robust. --- test/c/string_mapping.expect | 7 ++++++ test/c/string_mapping.sail | 45 ++++++++++++++++++++++++++++++++++++ test/typecheck/pass/tyvar_names.sail | 25 ++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 test/c/string_mapping.expect create mode 100644 test/c/string_mapping.sail create mode 100644 test/typecheck/pass/tyvar_names.sail (limited to 'test') diff --git a/test/c/string_mapping.expect b/test/c/string_mapping.expect new file mode 100644 index 00000000..9928ba1b --- /dev/null +++ b/test/c/string_mapping.expect @@ -0,0 +1,7 @@ +foo +bar +got true +foo +bar +got true +bazfooquux diff --git a/test/c/string_mapping.sail b/test/c/string_mapping.sail new file mode 100644 index 00000000..7c620817 --- /dev/null +++ b/test/c/string_mapping.sail @@ -0,0 +1,45 @@ +default Order dec + +$include +$include + +val test1 : string <-> (bool, int) + +mapping test1 = { + "foo" <-> (true, 3), + "b" ^ "ar" <-> (false, 2) +} + +val test2 : (bool, int) <-> string + +mapping test2 = { + (true, 3) <-> "f" ^ "oo", + (false, 2) <-> "bar" +} + +val test3 : string <-> int + +mapping test3 = { + "baz" ^ test1(true, 3) ^ "quux" <-> 6 +} + +val "print_endline" : string -> unit + +function main((): unit) -> unit = { + print_endline(test1(true, 3)); + print_endline(test1(false, 2)); + match test1("foo") { + (true, _) => print_endline("got true"), + _ => print_endline("fail") + }; + + print_endline(test2(true, 3)); + print_endline(test2(false, 2)); + match test2("foo") { + (true, _) => print_endline("got true"), + _ => print_endline("fail") + }; + + print_endline(test3(6)); + () +} \ No newline at end of file diff --git a/test/typecheck/pass/tyvar_names.sail b/test/typecheck/pass/tyvar_names.sail new file mode 100644 index 00000000..eb31307e --- /dev/null +++ b/test/typecheck/pass/tyvar_names.sail @@ -0,0 +1,25 @@ +default Order dec + +$include + +$option -dmagic_hash + +function main((): unit) -> unit = { + let x = (3 + 3) : {'n, 'n == 6. int('n)}; + _check(x : int('x#0)); + let y = (2 + 4) : {'n, 'n == 6. int('n)}; + _check(y : int('y#0)); + let x = 26 : {'n, 'n == 26. int('n)}; + _check(x : int('x#1)); + () +} + +function main2((): unit) -> unit = { + let x = (3 + 3) : {'n, 'n == 6. int('n)}; + _check(x : int('x#0)); + let y = (2 + 4) : {'n, 'n == 6. int('n)}; + _check(y : int('y#0)); + let x = 26 : {'n, 'n == 26. int('n)}; + _check(x : int('x#1)); + () +} \ No newline at end of file -- cgit v1.2.3