if (retnode->expr) {
if (check_expression(&retnode->expr)) return 1;
- if (!type_check_or_auto_cast(retnode->expr, semstate.expected_return_type)) {
+ if (!type_check_or_auto_cast(&retnode->expr, semstate.expected_return_type)) {
onyx_report_error(retnode->expr->token->pos,
"Expected to return a value of type '%s', returning value of type '%s'.",
type_get_name(semstate.expected_return_type),
fill_in_type((AstTyped *) arg);
if ((*param_type)->kind == Type_Kind_VarArgs) {
- if (!type_check_or_auto_cast(arg->value, (*param_type)->VarArgs.ptr_to_data->Pointer.elem))
+ if (!type_check_or_auto_cast(&arg->value, (*param_type)->VarArgs.ptr_to_data->Pointer.elem))
goto no_match;
}
- else if (!type_check_or_auto_cast(arg->value, *param_type)) goto no_match;
+ else if (!type_check_or_auto_cast(&arg->value, *param_type)) goto no_match;
param_type++;
arg = (AstArgument *) arg->next;
return NULL;
}
-typedef struct PolyArg {
- AstArgument* arg;
- u64 pos;
-} PolyArg;
-
typedef enum ArgState {
AS_Expecting_Exact,
AS_Expecting_Typed_VA,
// 8. If callee is an intrinsic, turn call into an Intrinsic_Call node
// 9. Check types of formal and actual params against each other, handling varargs
-
-
if (check_expression(&call->callee)) return 1;
AstFunction* callee = (AstFunction *) call->callee;
bh_arr(AstArgument *) arg_arr = NULL;
bh_arr_new(global_heap_allocator, arg_arr, call->arg_count);
- bh_arr(PolyArg) poly_args = NULL;
- bh_arr_new(global_heap_allocator, arg_arr, 1);
-
// NOTE: Check arguments
AstArgument* actual = call->arguments;
while (actual != NULL) {
return 1;
}
- if (actual->value->kind == Ast_Kind_Polymorphic_Proc) {
- bh_arr_push(poly_args, ((PolyArg) {
- .arg = actual,
- .pos = bh_arr_length(arg_arr),
- }));
- }
-
bh_arr_push(arg_arr, actual);
actual = (AstArgument *) actual->next;
}
return 1;
}
- bh_arr_each(PolyArg, pa, poly_args) {
- pa->arg->value = (AstTyped *) polymorphic_proc_lookup(
- (AstPolyProc *) pa->arg->value,
- PPLM_By_Function_Type,
- callee->type->Function.params[pa->pos],
- pa->arg->token->pos);
-
- if (pa->arg->value == NULL) return 1;
-
- pa->arg->value->flags |= Ast_Flag_Function_Used;
- }
-
if (callee->kind == Ast_Kind_Function) {
if (bh_arr_length(arg_arr) < bh_arr_length(callee->params)) {
while (bh_arr_length(arg_arr) < bh_arr_length(callee->params)
}
if (arg_pos >= bh_arr_length(arg_arr)) goto type_checking_done;
- if (!type_check_or_auto_cast(arg_arr[arg_pos]->value, formal_params[arg_pos])) {
+ if (!type_check_or_auto_cast(&arg_arr[arg_pos]->value, formal_params[arg_pos])) {
onyx_report_error(arg_arr[arg_pos]->token->pos,
"The function '%b' expects a value of type '%s' for %d%s parameter, got '%s'.",
callee->token->text, callee->token->length,
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)) {
+ if (!type_check_or_auto_cast(&arg_arr[arg_pos]->value, variadic_type)) {
onyx_report_error(arg_arr[arg_pos]->token->pos,
"The function '%b' expects a value of type '%s' for the variadic parameter, '%b', got '%s'.",
callee->token->text, callee->token->length,
callee->flags |= Ast_Flag_Function_Used;
call->arg_arr = arg_arr;
- bh_arr_free(poly_args);
-
return 0;
}
if (check_binaryop(&binop_node, 0)) return 1;
}
- if (!type_check_or_auto_cast(binop->right, 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),
onyx_report_error(binop->token->pos, "Cannot have auto cast on both sides of binary operator.");
return 1;
}
- else if (type_check_or_auto_cast(binop->left, rtype));
- else if (type_check_or_auto_cast(binop->right, ltype));
+ else if (type_check_or_auto_cast(&binop->left, rtype));
+ else if (type_check_or_auto_cast(&binop->right, ltype));
else {
onyx_report_error(binop->token->pos,
"Cannot compare '%s' to '%s'.",
onyx_report_error(binop->token->pos, "Cannot have auto cast on both sides of binary operator.");
return 1;
}
- else if (type_check_or_auto_cast(binop->left, binop->right->type));
- else if (type_check_or_auto_cast(binop->right, binop->left->type));
+ else if (type_check_or_auto_cast(&binop->left, binop->right->type));
+ else if (type_check_or_auto_cast(&binop->right, binop->left->type));
else {
onyx_report_error(binop->token->pos,
"Mismatched types for binary operation. left: '%s', right: '%s'.",
type_lookup_member_by_idx(sl->type, i, &smem);
Type* formal = smem.type;
- if (!type_check_or_auto_cast((*actual), formal)) {
+ if (!type_check_or_auto_cast(actual, formal)) {
onyx_report_error(sl->token->pos,
"Mismatched types for %d%s member named '%s', expected '%s', got '%s'.",
i + 1, bh_num_suffix(i + 1),
StructMember smem;
type_lookup_member(expected_range_type, "low", &smem);
- if (!type_check_or_auto_cast(range->left, smem.type)) {
+ if (!type_check_or_auto_cast(&range->left, smem.type)) {
onyx_report_error(range->token->pos, "Expected left side of range to be a 32-bit integer.");
return 1;
}
type_lookup_member(expected_range_type, "high", &smem);
- if (!type_check_or_auto_cast(range->right, smem.type)) {
+ if (!type_check_or_auto_cast(&range->right, smem.type)) {
onyx_report_error(range->token->pos, "Expected right side of range to be a 32-bit integer.");
return 1;
}
if (memres->type != NULL) {
Type* memres_type = memres->type;
- if (!type_check_or_auto_cast(memres->initial_value, memres_type)) {
+ if (!type_check_or_auto_cast(&memres->initial_value, memres_type)) {
onyx_report_error(memres->token->pos,
"Cannot assign value of type '%s' to a '%s'.",
type_get_name(memres_type),