harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 2f35a51210963a27182ace202bf5cd157b18da42
parent 3d54dc112121fd2e9fd09b28e373ddf853567168
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri,  1 Jan 2021 12:58:44 -0500

Add (basic) pointer test and fix nullable issue

Diffstat:
Msrc/type_store.c | 4++--
Atests/03-pointers.ha | 23+++++++++++++++++++++++
Mtests/configure | 3++-
3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -81,8 +81,8 @@ type_is_assignable(struct type_store *store, to->pointer.referent != from->pointer.referent) { return false; } - if (to->pointer.flags & PTR_NULLABLE) { - return from->pointer.flags & PTR_NULLABLE; + if (from->pointer.flags & PTR_NULLABLE) { + return to->pointer.flags & PTR_NULLABLE; } return true; default: diff --git a/tests/03-pointers.ha b/tests/03-pointers.ha @@ -0,0 +1,23 @@ +fn compfail(src: str) void; + +fn basics() void = { + let x = 42; + let y: *int = &x; + assert(*y == 42); + *y = 1337; + assert(x == 1337); +}; + +fn _nullable() void = { + let x: nullable *int = null; + assert(x == null: nullable *int); // TODO: type promotion + let y = 42; + x = &y; + assert(*(x: *int) == 42); + // TODO: Expected failures with nullable pointers +}; + +export fn main() void = { + basics(); + _nullable(); +}; diff --git a/tests/configure b/tests/configure @@ -5,7 +5,8 @@ tests() { for t in \ 00-constants \ 01-arrays \ - 02-integers + 02-integers \ + 03-pointers do cat <<EOF tests/$t: rt tests/$t.ha