From 858d5c1756b64f4973588424b8ba375136740510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Mon, 8 Mar 2021 20:53:01 +0100 Subject: order the return type correctly --- progs/tests/wrong_params.sy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/tests/wrong_params.sy b/progs/tests/wrong_params.sy index e49e89b..0082a3a 100644 --- a/progs/tests/wrong_params.sy +++ b/progs/tests/wrong_params.sy @@ -4,4 +4,4 @@ start :: fn { f } -// errors: [ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(Type::Void, Type::Int)] +// errors: [ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(Type::Int, Type::Void)] -- cgit v1.2.1 From 4e6ef21576d9ec6a8861246464b1905819b68efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Mon, 8 Mar 2021 21:57:52 +0100 Subject: fix some nice tests for the nullable_types --- progs/tests/nullable_types.sy | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 progs/tests/nullable_types.sy (limited to 'progs') diff --git a/progs/tests/nullable_types.sy b/progs/tests/nullable_types.sy new file mode 100644 index 0000000..2088c53 --- /dev/null +++ b/progs/tests/nullable_types.sy @@ -0,0 +1,33 @@ +test001 :: fn -> int { + a : int? = nil + a = 2 + ret a +} + +test002 :: fn b:bool -> int? { + if b { + ret nil + } else { + ret 0 + } +} + +// TODO(ed): Introduce type type! +test003 :: fn { + a := test002! false + a += 1 + a <=> 1 +} + + +start :: fn { + test001! + nil <=> test002! true + 0 <=> test002! false + q : bool? = true + q <=> true + q = nil + q <=> nil + test003! +} + -- cgit v1.2.1 From fe3909375bd0b200989b9d88158e8c3412b3d639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Mon, 8 Mar 2021 23:39:59 +0100 Subject: change how tuple comparison functions --- progs/tests/sub.sy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/tests/sub.sy b/progs/tests/sub.sy index e5d60f2..cca4f2c 100644 --- a/progs/tests/sub.sy +++ b/progs/tests/sub.sy @@ -1,3 +1,4 @@ start :: fn { - (1, -2, 3, -4) - (4, 3, -2, -1) <=> (-3, 1, 1, -5) + print (1, -2, 3, -4) - (4, 3, -2, -1) + (1, -2, 3, -4) - (4, 3, -2, -1) <=> (-3, -5, 5, -3) } -- cgit v1.2.1 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 (limited to 'progs') 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 From 30461c655f08e37f0758e0de137b679b789024cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Tue, 9 Mar 2021 17:41:57 +0100 Subject: fix functions as optional types --- progs/tests/union_types_simple.sy | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'progs') diff --git a/progs/tests/union_types_simple.sy b/progs/tests/union_types_simple.sy index 490717e..f6cf622 100644 --- a/progs/tests/union_types_simple.sy +++ b/progs/tests/union_types_simple.sy @@ -14,10 +14,23 @@ g :: fn a:bool -> int | (bool, bool) { } } +h :: fn a:bool -> int | fn -> int { + if a { + f :: fn -> int { ret 1 } + ret f + } else { + ret 1 + } +} + start :: fn { 1 <=> f! true nil <=> f! false (true, true) <=> g! false 1 <=> g! true f(true) <=> g(true) + + 1 <=> h! false + q :: h! true + 1 <=> q() } -- cgit v1.2.1