Merge pull request #3036 from laytan/error-when-c-vararg-is-not-on-last-param

error when #c_vararg is not applied to the last parameter
This commit is contained in:
gingerBill
2024-01-02 14:22:24 +00:00
committed by GitHub
+17 -17
View File
@@ -2070,33 +2070,33 @@ gb_internal bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc
type->Proc.diverging = pt->diverging; type->Proc.diverging = pt->diverging;
type->Proc.optional_ok = optional_ok; type->Proc.optional_ok = optional_ok;
if (param_count > 0) { bool is_polymorphic = false;
Entity *end = params->Tuple.variables[param_count-1]; for (isize i = 0; i < param_count; i++) {
if (end->flags&EntityFlag_CVarArg) { 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) { switch (cc) {
default: default:
type->Proc.c_vararg = true; type->Proc.c_vararg = true;
break; break;
case ProcCC_Odin: case ProcCC_Odin:
case ProcCC_Contextless: case ProcCC_Contextless:
error(end->token, "Calling convention does not support #c_vararg"); error(e->token, "Calling convention does not support #c_vararg");
break; 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++) { for (isize i = 0; i < result_count; i++) {
Entity *e = results->Tuple.variables[i]; Entity *e = results->Tuple.variables[i];
if (e->kind != Entity_Variable) { if (e->kind != Entity_Variable) {