import std.algorithm;
void main() {
auto arr = [ 1, 3, 4, 2, 3, 8, 2 ];
int dummy;
switch(0) {
case 1:
auto f = (int a, int b) { return a - dummy < b; };
sort!f(arr);
break;
default:
auto f = (int a, int b) { return a - dummy < b; };
sort!f(arr);
}
}
This code causes AV, renaming second f to f2 runs successful.
Comment #1 by dlang-bugzilla — 2017-07-21T04:33:04Z
Reduced:
////// test.d /////
void fun(alias x)()
{
assert(x == 1);
}
void main()
{
if (false)
{
int i = 0;
fun!i();
}
{
int i = 1;
fun!i();
}
}
///////////////////
The problem is that both fun!i instantiations have the same mangled name, even though they refer to different variables and have different code.
The mangled name of local variables should have some sort of index in them.
Comment #2 by bugzilla — 2020-08-09T10:21:37Z
If they're declared as 'static' the current compiler will issue an error about a name collision. Any fix for this should use a similar mechanism.
Comment #3 by bugzilla — 2020-08-09T10:50:45Z
*** Issue 13617 has been marked as a duplicate of this issue. ***
Comment #4 by moonlightsentinel — 2021-07-05T12:54:52Z