From 30d794653d949d80c00feefe4eb360ba999ca1b5 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 24 Sep 2023 20:17:41 +0200 Subject: [PATCH] Resolve type fully before checking casts, addressing #1013. Correctly show the error location when a method is missing its single argument #1012. --- src/compiler/abi/c_abi.c | 2 -- src/compiler/sema_casts.c | 1 + src/compiler/sema_expr.c | 18 +++++++----------- src/version.h | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/compiler/abi/c_abi.c b/src/compiler/abi/c_abi.c index fc721eced..ba1795dc4 100644 --- a/src/compiler/abi/c_abi.c +++ b/src/compiler/abi/c_abi.c @@ -18,8 +18,6 @@ ABIArgInfo *abi_arg_ignore(void) return &info; } - - bool abi_type_is_integer(AbiType type) { return !abi_type_is_type(type) || type_is_integer(type.type); diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 66f22efd4..74ae01e00 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -306,6 +306,7 @@ static bool cast_if_valid(SemaContext *context, Expr *expr, Type *to_type, bool .expr = expr, .context = context }; + if (!sema_resolve_type_decl(context, to)) return false; if (!cast_is_allowed(&cc, is_explicit, false)) { return false; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index a6063d82e..795dd4ff8 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1332,21 +1332,17 @@ INLINE bool sema_call_expand_arguments(SemaContext *context, CalledDecl *callee, sema_error_at_after(args[num_args - 1]->span, "Expected '.%s = ...' after this argument.", param->name); return false; } - if (num_args) + if (num_args > (callee->struct_var ? 1 : 0)) { unsigned needed = func_param_count - num_args; - SEMA_ERROR(args[num_args - 1], - "Expected %d more %s after this one, did you forget %s?", - needed, needed == 1 ? "argument" : "arguments", needed == 1 ? "it" : "them"); + RETURN_SEMA_ERROR(args[num_args - 1], + "Expected %d more %s after this one, did you forget %s?", + needed, needed == 1 ? "argument" : "arguments", needed == 1 ? "it" : "them"); } - else - { - SEMA_ERROR(call, "'%s' expects %d parameters, but none was provided.", callee->name, func_param_count); - } - return false; + RETURN_SEMA_ERROR(call, "'%s' expects %d parameter(s), but none was provided.", + callee->name, callee->struct_var ? func_param_count - 1 : func_param_count); } - SEMA_ERROR(call, "The parameter '%s' must be set, did you forget it?", param->name); - return false; + RETURN_SEMA_ERROR(call, "The parameter '%s' must be set, did you forget it?", param->name); } call->call_expr.arguments = actual_args; return true; diff --git a/src/version.h b/src/version.h index f02d05667..71391b196 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.659" \ No newline at end of file +#define COMPILER_VERSION "0.4.660" \ No newline at end of file