harec

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

commit e8895c2ff44df822d444d7e1727cb289682a1d94
parent b321f939e42565cc8a1c77753d9aa6bb101a43e6
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Sat, 12 Mar 2022 15:33:04 +0100

type_is_assignable: fix pointer to array assignability logic

Fixes: https://todo.sr.ht/~sircmpwn/hare/589
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Msrc/types.c | 4++--
Mtests/01-arrays.ha | 12++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/types.c b/src/types.c @@ -772,8 +772,8 @@ type_is_assignable(const struct type *to, const struct type *from) case STORAGE_VOID: break; case STORAGE_ARRAY: - if (type_is_assignable(to_secondary, from_secondary)) { - return true; + if (!type_is_assignable(to_secondary, from_secondary)) { + return false; } break; default: diff --git a/tests/01-arrays.ha b/tests/01-arrays.ha @@ -1,3 +1,5 @@ +use rt; + fn indexing() void = { let x = [1, 2, 3]; let y = &x; @@ -45,6 +47,16 @@ fn assignment() void = { z = y; assert(y[0] == 1 && y[1] == 2 && y[2] == 3); assert(z[0] == 1 && z[1] == 2 && z[2] == 3); + + assert(rt::compile(" + export fn main() void = { + let a: [3]uint = [1u,2u,3u]; + let b: uint = 0; + + let ptr: *[3]uint = &a; + ptr = &b; + }; + ") != 0); }; fn param(x: [3]int) void = {