From 326fc501e2992a1cd2faf41ccb3fc1273c276228 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 2 Jul 2024 00:36:05 +0200 Subject: [PATCH] Simplified @is_comparer --- lib/std/sort/sort.c3 | 28 ++++++---------------------- src/compiler/sema_casts.c | 7 ++----- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/lib/std/sort/sort.c3 b/lib/std/sort/sort.c3 index e2ecad10f..c9f541752 100644 --- a/lib/std/sort/sort.c3 +++ b/lib/std/sort/sort.c3 @@ -13,26 +13,10 @@ macro usz @len_from_list(&list) macro bool @is_comparer(#cmp, #list) { var $Type = $typeof(#cmp); - $if $and($Type.kindof == FUNC, $Type.returns.kindof == SIGNED_INT): - var $params = $Type.params; - $if $params.len != 2: - return false; - $else - $if $params[0] != $params[1]: - return false; - $else - var $element = @typeid(#list[0]); - $switch - $case $element == $params[0]: - return true; - $case $and($params[0].kindof == POINTER, $params[0].inner == $element): - return true; - $default: - return false; - $endswitch - $endif - $endif - $else - return false; - $endif + $switch + $case $or($Type.kindof != FUNC, $Type.returns.kindof != SIGNED_INT): return false; + $case $defined(#cmp(#list[0], #list[0])): return true; + $case $defined(#cmp(&&(#list[0]), &&(#list[0]))): return true; + $default: return false; + $endswitch } \ No newline at end of file diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 664132927..2ef0616f1 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -104,11 +104,8 @@ static bool cast_is_allowed(CastContext *cc, bool is_explicit, bool is_silent) // No rule => no if (!rule) { - if (!is_silent) - { - RETURN_CAST_ERROR(cc->expr, "You cannot cast %s to %s.", type_quoted_error_string(cc->expr->type), type_quoted_error_string(cc->to_type)); - } - return false; + if (is_silent) return false; + RETURN_CAST_ERROR(cc->expr, "You cannot cast %s to %s.", type_quoted_error_string(cc->expr->type), type_quoted_error_string(cc->to_type)); } return rule(cc, is_explicit, is_silent);