harec

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

commit b95fe43114f4c5ffa80c3593192edaf97427aac3
parent 8b3e46abf8c26b103175dd60d7236b8b393cf661
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  9 Aug 2021 10:05:25 +0200

gen: implement cast silce => *array

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 5+++--
Mtests/907-casts.ha | 8++++++++
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -748,8 +748,9 @@ gen_expr_cast(struct gen_context *ctx, const struct expression *expr) switch (type_dealias(to)->storage) { case STORAGE_POINTER: if (type_dealias(from)->storage == STORAGE_SLICE) { - // Cast slice to pointer - assert(0); // TODO + struct gen_value value = gen_expr(ctx, expr->cast.value); + value.type = to; + return gen_load(ctx, value); } break; case STORAGE_VOID: diff --git a/tests/907-casts.ha b/tests/907-casts.ha @@ -30,8 +30,16 @@ fn floats() void = { assert(y == 13); }; +fn slices() void = { + let x: [_]int = [1, 2, 3, 4]; + let y: []int = x; + let z = y: *[*]int; + assert(z == &x); +}; + export fn main() int = { integers(); floats(); + slices(); return 0; };