hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 83084931d245ca0c0dda8fcc0a14badb450293e3
parent fa48e54c778b309cbc29fc2d36ba111e7ad8bfc7
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Sat, 26 Mar 2022 01:43:38 +0100

use type assertion with nullable types in some places

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Mcmd/hare/plan.ha | 8+-------
Mhare/parse/expr.ha | 4++--
Mhare/types/lookup.ha | 3+--
Mhare/unit/process.ha | 3+--
Miobus/io_uring/bus.ha | 6+-----
Mlinux/io_uring/cqe.ha | 3+--
Mmime/lookup.ha | 20+++++---------------
Msort/+test.ha | 8++------
8 files changed, 14 insertions(+), 41 deletions(-)

diff --git a/cmd/hare/plan.ha b/cmd/hare/plan.ha @@ -170,14 +170,8 @@ fn plan_execute(plan: *plan, verbose: bool) (void | !exec::exit_status) = { break; }; }; - // TODO: This can be a type assertion - let task = match (next) { - case null => - abort(); - case let t: *task => - yield t; - }; + let task = next as *task; match (task.module) { case let s: str => plan.progress.current_module = s; diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -694,8 +694,8 @@ fn indexing(lexer: *lex::lexer, lvalue: ast::expr) (ast::expr | error) = { } else ast::access_index { object = alloc(lvalue), index = { - assert(start != null && end == null); - yield start: *ast::expr; + assert(end == null); + yield start as *ast::expr; }, }, }; diff --git a/hare/types/lookup.ha b/hare/types/lookup.ha @@ -7,8 +7,7 @@ use hare::ast; export fn dealias(t: *_type) const *_type = { for (true) match (t.repr) { case let a: alias => - assert(a.secondary != null); - t = a.secondary: const *_type; + t = a.secondary as const *_type; case => break; }; diff --git a/hare/unit/process.ha b/hare/unit/process.ha @@ -438,6 +438,5 @@ fn process_return(ctx: *context, aexpr: *ast::expr) (*expr | error) = { assert(ret_expr.terminates); assert(ret_expr.result.repr as types::builtin == types::builtin::VOID); const rval = ret_expr.expr as _return; - assert(rval != null); - assert((rval: *expr).expr is constant); + assert((rval as *expr).expr is constant); }; diff --git a/iobus/io_uring/bus.ha b/iobus/io_uring/bus.ha @@ -94,11 +94,7 @@ fn _dispatch(bus: *bus) (result | error) = { return err: error; case uint => void; }; - match (io_uring::peek(&bus.uring)?) { - case null => abort(); - case let cqe: *io_uring::cqe => - return cqe: result; - }; + return io_uring::peek(&bus.uring)? as *io_uring::cqe; }; // Registers a file with the iobus, returning a [[registered_file]] object to diff --git a/linux/io_uring/cqe.ha b/linux/io_uring/cqe.ha @@ -21,8 +21,7 @@ export fn wait(ring: *io_uring) (*cqe | error) = { case let err: error => return err; case let cq: nullable *cqe => - assert(cq != null); // XXX: Correct? - return cq: *cqe; + return cq as *cqe; // XXX: Correct? }; }; diff --git a/mime/lookup.ha b/mime/lookup.ha @@ -20,16 +20,12 @@ export fn lookup_mime(mime: str) const nullable *mimetype = { @test fn lookup_mime() void = { assert(lookup_mime("foo/bar") == null); - const result = lookup_mime("text/plain"); - assert(result != null); - const result = result: *mimetype; + const result = lookup_mime("text/plain") as *mimetype; assert(result.mime == "text/plain"); assert(len(result.exts) == 1); assert(result.exts[0] == "txt"); - const result = lookup_mime("text/x-hare"); - assert(result != null); - const result = result: *mimetype; + const result = lookup_mime("text/x-hare") as *mimetype; assert(result.mime == "text/x-hare"); assert(len(result.exts) == 1); assert(result.exts[0] == "ha"); @@ -56,21 +52,15 @@ export fn lookup_ext(ext: str) const nullable *mimetype = { assert(lookup_ext("foo") == null); assert(lookup_ext(".foo") == null); - const result = lookup_ext("txt"); - assert(result != null); - const result = result: *mimetype; + const result = lookup_ext("txt") as *mimetype; assert(result.mime == "text/plain"); assert(len(result.exts) == 1); assert(result.exts[0] == "txt"); - const result = lookup_ext(".txt"); - assert(result != null); - const result = result: *mimetype; + const result = lookup_ext(".txt") as *mimetype; assert(result.mime == "text/plain"); - const result = lookup_ext("ha"); - assert(result != null); - const result = result: *mimetype; + const result = lookup_ext("ha") as *mimetype; assert(result.mime == "text/x-hare"); assert(len(result.exts) == 1); assert(result.exts[0] == "ha"); diff --git a/sort/+test.ha b/sort/+test.ha @@ -11,12 +11,8 @@ fn ncmp(a: const *void, b: const *void) int = { const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; for (let i = 0z; i < len(nums); i += 1) { const key = nums[i]; - match (search(nums[..], size(int), &key, &ncmp): nullable *int) { - case null => - abort(); - case let p: *int => - assert(p == &nums[i] && *p == nums[i]); - }; + let p = search(nums[..], size(int), &key, &ncmp) as *int; + assert(p == &nums[i] && *p == nums[i]); }; const key = 1337; assert(search(nums[..], size(int), &key, &ncmp) == null);