- Shadowing not detected for generic declarations #2876

This commit is contained in:
Christoffer Lerno
2026-02-05 01:33:47 +01:00
parent dcf695c726
commit 71b673d241
5 changed files with 22 additions and 16 deletions

View File

@@ -20,12 +20,6 @@ macro void insertionsort(list, cmp = ..., context = ...) @builtin @safemacro
module std::sort <Type, CmpFn, Context> @private;
alias ElementType = $typeof(((Type){})[0]);
const bool IS_SLICE = Type.kindof == SLICE;
alias ListType = $typefrom(IS_SLICE ??? Type : Type*);
macro ElementType list_get(ListType l, i) => IS_SLICE ??? l[i] : (*l)[i];
macro ElementType* list_get_ref(ListType l, i) => IS_SLICE ??? &l[i] : &(*l)[i];
fn void isort(ListType list, usz low, usz high, CmpFn comp, Context context) @noinline @private
{
var $has_cmp = $typeof(comp) != TypeNotSet;

View File

@@ -43,16 +43,6 @@ macro quickselect(list, isz k, cmp = ..., context = ...) @builtin
module std::sort <Type, CmpFn, Context> @private;
alias ElementType = $typeof(((Type){})[0]);
const bool IS_SLICE = Type.kindof == SLICE;
alias ListType = $typefrom(IS_SLICE ??? Type : Type*);
macro list_get(ListType l, i) @if(!IS_SLICE) => (*l)[i];
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];
macro list_set(ListType l, i, v) @if(!IS_SLICE) => (*l)[i] = v;
macro list_set(ListType l, i, v) @if(IS_SLICE) => l[i] = v;
struct StackElementItem @private
{
isz low;

View File

@@ -0,0 +1,11 @@
module std::sort <Type, CmpFn, Context> @private;
alias ElementType = $typeof(((Type){})[0]);
const bool IS_SLICE = Type.kindof == SLICE;
alias ListType = $typefrom(IS_SLICE ??? Type : Type*);
macro ElementType list_get(ListType l, i) @if(!IS_SLICE) => (*l)[i];
macro ElementType list_get(ListType l, i) @if(IS_SLICE) => l[i];
macro ElementType* list_get_ref(ListType l, i) @if(!IS_SLICE) => &(*l)[i];
macro ElementType* list_get_ref(ListType l, i) @if(IS_SLICE) => &l[i];
macro void list_set(ListType l, i, v) @if(!IS_SLICE) => (*l)[i] = v;
macro void list_set(ListType l, i, v) @if(IS_SLICE) => l[i] = v;

View File

@@ -15,6 +15,7 @@
- Regression where nested lambdas would be evaluated twice.
- Compiler crash when using arrays of vectors in lists. #2889
- Fix `list[0].i = 5` when `list[0]` returns a pointer. #2888
- Shadowing not detected for generic declarations #2876
## 0.7.9 Change list

View File

@@ -125,6 +125,16 @@ void decl_register(CompilationUnit *unit, Decl *decl)
if (decl->is_templated)
{
DEBUG_LOG("Registering generic symbol '%s' in %s.", decl->name, unit->module->name->module);
Decl *instance = declptr(decl->instance_id);
FOREACH (Decl *, other, instance->instance_decl.generated_decls)
{
if (other->name != decl->name) continue;
if (other->visibility == VISIBLE_LOCAL && decl->visibility == VISIBLE_LOCAL && decl->unit != other->unit) continue;
sema_shadow_error(NULL, decl, other);
decl_poison(decl);
decl_poison(other);
return;
}
vec_add(declptr(decl->instance_id)->instance_decl.generated_decls, decl);
return;
}