[qfcc] Check all generic function variants for dups

Checking only the last function to be added results in false negatives
and thus duplicates when defining a generic function. eg:

    genFType radians (genFType degrees);
    genDType radians (genDType degrees);
    genFType radians (genFType degrees) = #0;
    genDType radians (genDType degrees) = #0;
This commit is contained in:
Bill Currie 2024-08-27 14:41:38 +09:00
parent c236129bbe
commit 4f5fcbd819

View file

@ -133,6 +133,8 @@ cmp_genparams (genfunc_t *g1, genparam_t *p1, genfunc_t *g2, genparam_t *p2)
void
add_generic_function (genfunc_t *genfunc)
{
auto name = genfunc->name;
for (int i = 0; i < genfunc->num_types; i++) {
auto gentype = &genfunc->types[i];
if (gentype->compute && gentype->valid_types) {
@ -154,16 +156,18 @@ add_generic_function (genfunc_t *genfunc)
}
}
if (!gen_params) {
internal_error (0, "%s has no generic parameters", genfunc->name);
internal_error (0, "%s has no generic parameters", name);
}
if (!genfunc->ret_type) {
internal_error (0, "%s has no return type", genfunc->name);
internal_error (0, "%s has no return type", name);
}
check_generic_param (genfunc->ret_type, genfunc);
bool is_new = true;
genfunc_t *old = Hash_Find (generic_functions, genfunc->name);
if (old && old->num_params == genfunc->num_params) {
auto old_list = (genfunc_t **) Hash_FindList (generic_functions, name);
for (auto o = old_list; is_new && o && *o; o++) {
auto old = *o;
if (old->num_params == genfunc->num_params) {
is_new = false;
for (int i = 0; i < genfunc->num_params; i++) {
if (!cmp_genparams (genfunc, &genfunc->params[i],
@ -178,6 +182,7 @@ add_generic_function (genfunc_t *genfunc)
return;
}
}
}
if (is_new) {
Hash_Add (generic_functions, genfunc);