aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorFourteenBrush <naessensarthur2@protonmail.com>2024-01-25 10:15:25 +0100
committerFourteenBrush <naessensarthur2@protonmail.com>2024-01-25 10:15:25 +0100
commit967ccfc7ccc0f76c653ff4bb625bac60e89a7904 (patch)
treef989a0f99337c7a0c93ee84249d73ec0c33e306d /src/check_type.cpp
parent712ae1c5ac73493498aa8e5076d91a6558337117 (diff)
parent9cfd4a953e2a7d19237891993b643b2d1477f8b3 (diff)
Merge branch 'master' of https://github.com/FourteenBrush/Odin
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index d66b196bc..a95026711 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -2070,33 +2070,33 @@ gb_internal bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc
type->Proc.diverging = pt->diverging;
type->Proc.optional_ok = optional_ok;
- if (param_count > 0) {
- Entity *end = params->Tuple.variables[param_count-1];
- if (end->flags&EntityFlag_CVarArg) {
+ bool is_polymorphic = false;
+ for (isize i = 0; i < param_count; i++) {
+ Entity *e = params->Tuple.variables[i];
+
+ if (e->kind != Entity_Variable) {
+ is_polymorphic = true;
+ } else if (is_type_polymorphic(e->type)) {
+ is_polymorphic = true;
+ }
+
+ if (e->flags&EntityFlag_CVarArg) {
+ if (i != param_count - 1) {
+ error(e->token, "#c_vararg can only be applied to the last parameter");
+ continue;
+ }
+
switch (cc) {
default:
type->Proc.c_vararg = true;
break;
case ProcCC_Odin:
case ProcCC_Contextless:
- error(end->token, "Calling convention does not support #c_vararg");
+ error(e->token, "Calling convention does not support #c_vararg");
break;
}
}
}
-
-
- bool is_polymorphic = false;
- for (isize i = 0; i < param_count; i++) {
- Entity *e = params->Tuple.variables[i];
- if (e->kind != Entity_Variable) {
- is_polymorphic = true;
- break;
- } else if (is_type_polymorphic(e->type)) {
- is_polymorphic = true;
- break;
- }
- }
for (isize i = 0; i < result_count; i++) {
Entity *e = results->Tuple.variables[i];
if (e->kind != Entity_Variable) {
@@ -2702,14 +2702,13 @@ gb_internal bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, T
check_expr_or_type(&c, &o, pt->type);
if (o.mode != Addressing_Invalid && o.mode != Addressing_Type) {
// NOTE(bill): call check_type_expr again to get a consistent error message
- begin_error_block();
+ ERROR_BLOCK();
elem = check_type_expr(&c, pt->type, nullptr);
if (o.mode == Addressing_Variable) {
gbString s = expr_to_string(pt->type);
error_line("\tSuggestion: ^ is used for pointer types, did you mean '&%s'?\n", s);
gb_string_free(s);
}
- end_error_block();
} else {
elem = o.type;
}