aboutsummaryrefslogtreecommitdiffstats
path: root/progs
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-03-08 23:40:16 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-03-08 23:40:16 +0100
commit50e3477ed34697be12890081b03d8412703ba8b3 (patch)
treefc5c89de353de15b60b475d3a7a0d568db002905 /progs
parentfe3909375bd0b200989b9d88158e8c3412b3d639 (diff)
downloadsylt-50e3477ed34697be12890081b03d8412703ba8b3.tar.gz
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.
Diffstat (limited to 'progs')
-rw-r--r--progs/tests/union_types_simple.sy23
-rw-r--r--progs/tests/union_types_simple_faulty.sy25
2 files changed, 48 insertions, 0 deletions
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(_, _) ]