From 50e3477ed34697be12890081b03d8412703ba8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Mon, 8 Mar 2021 23:40:16 +0100 Subject: add in fancy tests for union types Functions in union return-types aren't callable, because the call code is a bit wack. A nice starting point though. --- progs/tests/union_types_simple.sy | 23 +++++++++++++++++++++++ progs/tests/union_types_simple_faulty.sy | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 progs/tests/union_types_simple.sy create mode 100644 progs/tests/union_types_simple_faulty.sy diff --git a/progs/tests/union_types_simple.sy b/progs/tests/union_types_simple.sy new file mode 100644 index 0000000..490717e --- /dev/null +++ b/progs/tests/union_types_simple.sy @@ -0,0 +1,23 @@ +f :: fn a:bool -> int | str | void { + if a { + ret 1 + } else { + ret + } +} + +g :: fn a:bool -> int | (bool, bool) { + if a { + ret 1 + } else { + ret (true, true) + } +} + +start :: fn { + 1 <=> f! true + nil <=> f! false + (true, true) <=> g! false + 1 <=> g! true + f(true) <=> g(true) +} diff --git a/progs/tests/union_types_simple_faulty.sy b/progs/tests/union_types_simple_faulty.sy new file mode 100644 index 0000000..b742054 --- /dev/null +++ b/progs/tests/union_types_simple_faulty.sy @@ -0,0 +1,25 @@ +f :: fn a:bool -> int | void { + if a { + ret 1 + } else { + ret "hello!" + } +} + +g :: fn a:bool -> int | (bool, bool) { + if a { + ret 1 + } else { + ret (true, 1.0) + } +} + +start :: fn { + 0 <=> f! true + 0.0 <=> f! false + ("hello!", "there") <=> g! false + 1 <=> g! true + f(true) <=> g(true) +} + +// errors: [ ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(_, _), ErrorKind::TypeError(_, _), ErrorKind::TypeError(_, _) ] -- cgit v1.2.1