enum test = q{
unittest {}
};
mixin(test);
unittest {
assert(false); // this never runs
}
void main() {
}
The mixed-in unittest hides the other unittest because the same name is generated for both.
Comment #1 by maxsamukha — 2021-02-10T11:25:19Z
Same with static constructors:
enum c = q{
static this() {}
};
mixin(c);
static this() {
assert(false);
}
void main() {
}
Comment #2 by b2.temp — 2021-02-10T13:32:23Z
You say this never runs but I see rather that this does not even compile, ehre I get, using dmd ~master:
/tmp/temp_7FC8FF6B4A50.d-mixin-5:6:1: Error: function `temp_7FC8FF6B4A50.__unittest_L6_C1()` conflicts with previous declaration at /tmp/temp_7FC8FF6B4A50.d:6:1
although this is still a bug.
Comment #3 by maxsamukha — 2021-02-10T14:46:51Z
I've tried the latest dmd, and it does detect the name conflict. Older versions (v2.092.1 in our case) produce runnable binaries (linker warns about changed symbol size, though).
Comment #4 by b2.temp — 2021-02-10T16:06:18Z
There should not be conflicts. DMD has a special function in its Identifier class that was exactly designed to prevent such conflicts. That's why you see "L" and "C" in the mangle BTW, so definitively a bug.
Comment #5 by maxsamukha — 2021-02-10T17:42:35Z
(In reply to Basile-z from comment #4)
> There should not be conflicts. DMD has a special function in its Identifier
> class that was exactly designed to prevent such conflicts. That's why you
> see "L" and "C" in the mangle BTW, so definitively a bug.
Yes, it's a bug. I was replying to the part where you say that the test case doesn't compile - it indeed doesn't with newer versions of the compiler.
Comment #6 by robert.schadek — 2024-12-13T19:14:38Z