harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 5340b82dce0fb4ed807ca182c713bb70ae67a3fb
parent 1b592803951d5068506f1dc961d30c6536abaec5
Author: Sebastian <sebastian@sebsite.pw>
Date:   Tue, 11 Oct 2022 10:52:50 -0400

check: allow casting rconst to more integer types

This fixes an assertion failure, and it is required by the spec, which
allows rconst to be promoted to any integer type or rune.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Msrc/check.c | 6++++++
Mtests/00-constants.ha | 5+++++
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -1452,6 +1452,12 @@ check_expr_cast(struct context *ctx, case STORAGE_U64: case STORAGE_I64: case STORAGE_U32: + case STORAGE_UINT: + case STORAGE_SIZE: + case STORAGE_UINTPTR: + break; + case STORAGE_I32: + max = INT32_MAX; break; case STORAGE_U16: max = UINT16_MAX; diff --git a/tests/00-constants.ha b/tests/00-constants.ha @@ -87,8 +87,13 @@ fn assignment() void = { rtu1 = 'a'; rtu2 = 'a'; rtu3 = 'a'; + assert(rtu3 is rune); assert(compile("export fn main() void = { let rtu4: (u32 | u64 | void) = void; rtu4 = 'a'; };") as exited != EXIT_SUCCESS); assert(compile("export fn main() void = { let rtu5: (str | void) = void; rtu5 = 'a'; };") as exited != EXIT_SUCCESS); + + let u2: uint = 'a'; + let u2: uintptr = 'a'; + let z: size = 'a'; }; fn aggregates() void = {