~turminal/hare

baa25302acad2e1435841d2a771c62baa21236d8 — Bor Grošelj Simić 2 years ago 11a9690 1
use type assertion with nullable types in some places
3 files changed, 4 insertions(+), 15 deletions(-)

M cmd/hare/plan.ha
M hare/types/lookup.ha
M sort/+test.ha
M cmd/hare/plan.ha => cmd/hare/plan.ha +1 -7
@@ 176,14 176,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;

M hare/types/lookup.ha => hare/types/lookup.ha +1 -2
@@ 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;
	};

M sort/+test.ha => sort/+test.ha +2 -6
@@ 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);