From: Brendan Hansen Date: Wed, 30 Sep 2020 03:19:26 +0000 (-0500) Subject: added auto casting on assignment and proper checking on boolean not X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ca9b85e6b89e16a545cdacf38cdeaf13395b6675;p=onyx.git added auto casting on assignment and proper checking on boolean not --- diff --git a/onyx b/onyx index f046cfd1..3e0aae99 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 4b1a3261..407a60bc 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -430,7 +430,7 @@ b32 check_call(AstCall* call) { ArgState arg_state = AS_Expecting_Exact; i32 arg_pos = 0; - while (1) { + while (1) { switch (arg_state) { case AS_Expecting_Exact: { if (arg_pos >= callee->type->Function.param_count) goto type_checking_done; @@ -444,7 +444,7 @@ b32 check_call(AstCall* call) { // CLEANUP POTENTIAL BUG if the builtin_vararg_type_type is ever rebuilt if (formal_params[arg_pos] == builtin_vararg_type_type) { - arg_state = AS_Expecting_Untyped_VA; + arg_state = AS_Expecting_Untyped_VA; continue; } @@ -466,7 +466,7 @@ b32 check_call(AstCall* call) { case AS_Expecting_Typed_VA: { call->va_kind = VA_Kind_Typed; - + if (arg_pos >= bh_arr_length(arg_arr)) goto type_checking_done; if (!type_check_or_auto_cast(arg_arr[arg_pos]->value, variadic_type)) { onyx_report_error(arg_arr[arg_pos]->token->pos, @@ -581,7 +581,7 @@ b32 check_binop_assignment(AstBinaryOp* binop, b32 assignment_is_ok) { if (check_binaryop(&binop_node, 0)) return 1; } - if (!types_are_compatible(binop->right->type, binop->left->type)) { + if (!type_check_or_auto_cast(binop->right, binop->left->type)) { onyx_report_error(binop->token->pos, "Cannot assign value of type '%s' to a '%s'.", type_get_name(binop->right->type), @@ -820,6 +820,15 @@ b32 check_unaryop(AstUnaryOp** punop) { unaryop->type = unaryop->expr->type; } + if (unaryop->operation == Unary_Op_Not) { + if (!type_is_bool(unaryop->expr->type)) { + onyx_report_error(unaryop->token->pos, + "Bool negation operator expected bool type, got '%s'.", + type_get_name(unaryop->expr->type)); + return 1; + } + } + if (unaryop->operation == Unary_Op_Bitwise_Not) { if (!type_is_integer(unaryop->expr->type)) { onyx_report_error(unaryop->token->pos,