From 2c55d6e2202f47b8cfe06239033bb367acf5139f Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 5 Feb 2026 18:43:54 +0100 Subject: [PATCH] Further fix shadowing of generics --- lib/std/sort/countingsort.c3 | 6 +++--- src/compiler/semantic_analyser.c | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/std/sort/countingsort.c3 b/lib/std/sort/countingsort.c3 index 34b4ad2b2..ea656570e 100644 --- a/lib/std/sort/countingsort.c3 +++ b/lib/std/sort/countingsort.c3 @@ -41,7 +41,7 @@ macro void quicksort_indexed(list, start, end, cmp = ..., context = ...) @builti $endif } -module std::sort @private; +module std::sort @local; alias Counts @private = usz[256]; alias Ranges @private = usz[257]; @@ -66,12 +66,12 @@ macro list_get(ListType l, i) @if(IS_SLICE) => l[i]; macro list_get_ref(ListType l, i) @if(!IS_SLICE) => &(*l)[i]; macro list_get_ref(ListType l, i) @if(IS_SLICE) => &l[i]; -fn void csort(ListType list, usz low, usz high, KeyFn key_fn, uint byte_idx) @if (!NO_KEY_FN) +fn void csort(ListType list, usz low, usz high, KeyFn key_fn, uint byte_idx) @if (!NO_KEY_FN) @private { _csort(list, low, high, byte_idx, key_fn); } -fn void csort(ListType list, usz low, usz high, uint byte_idx) @if (NO_KEY_FN) +fn void csort(ListType list, usz low, usz high, uint byte_idx) @if (NO_KEY_FN) @private { _csort(list, low, high, byte_idx); } diff --git a/src/compiler/semantic_analyser.c b/src/compiler/semantic_analyser.c index e132d3223..1b7503ce3 100644 --- a/src/compiler/semantic_analyser.c +++ b/src/compiler/semantic_analyser.c @@ -276,8 +276,30 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls) if (decl->func_decl.type_parent) continue; break; } - htable_set(&unit->module->symbols, (void *)decl->name, decl); - htable_set(&unit->local_symbols, (void *)decl->name, decl); + Decl *old; + if (decl->visibility < VISIBLE_LOCAL) + { + if ((old = htable_set(&unit->module->symbols, (void *)decl->name, decl))) + { + if (old->generic_id != decl->generic_id) + { + sema_shadow_error(NULL, decl, old); + decl_poison(decl); + decl_poison(old); + continue; + } + } + } + if ((old = htable_set(&unit->local_symbols, (void *)decl->name, decl))) + { + if (old->generic_id != decl->generic_id) + { + sema_shadow_error(NULL, decl, old); + decl_poison(decl); + decl_poison(old); + continue; + } + } if (decl->visibility == VISIBLE_PUBLIC) {