diff --git a/lib/std/sort/insertionsort.c3 b/lib/std/sort/insertionsort.c3 index 9bfbffaf4..18ba4bfc1 100644 --- a/lib/std/sort/insertionsort.c3 +++ b/lib/std/sort/insertionsort.c3 @@ -20,12 +20,6 @@ macro void insertionsort(list, cmp = ..., context = ...) @builtin @safemacro module std::sort @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; diff --git a/lib/std/sort/quicksort.c3 b/lib/std/sort/quicksort.c3 index 2502d3e7b..f54dbf4f1 100644 --- a/lib/std/sort/quicksort.c3 +++ b/lib/std/sort/quicksort.c3 @@ -43,16 +43,6 @@ macro quickselect(list, isz k, cmp = ..., context = ...) @builtin module std::sort @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; diff --git a/lib/std/sort/sort_common_private.c3 b/lib/std/sort/sort_common_private.c3 new file mode 100644 index 000000000..ee57d56ea --- /dev/null +++ b/lib/std/sort/sort_common_private.c3 @@ -0,0 +1,11 @@ +module std::sort @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; \ No newline at end of file diff --git a/releasenotes.md b/releasenotes.md index e28a74b82..692a75b58 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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 diff --git a/src/compiler/context.c b/src/compiler/context.c index da51cb4a7..8664dad9b 100644 --- a/src/compiler/context.c +++ b/src/compiler/context.c @@ -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; }