digitalmars.D.bugs - [Issue 18880] New: [REG2.079] Miscompilation of unittests when two
- d-bugmail puremagic.com (45/45) May 19 2018 https://issues.dlang.org/show_bug.cgi?id=18880
https://issues.dlang.org/show_bug.cgi?id=18880 Issue ID: 18880 Summary: [REG2.079] Miscompilation of unittests when two are mixed-in on one line Product: D Version: D2 Hardware: x86 OS: Mac OS X Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: johanengelen weka.io With the change to deterministic unittest function naming, this bug was introduced: When N unittests are mixed-in on the same line, the first one is run N times. Testcase: ``` mixin(genTest("666")); mixin(genTest("777")); int i; string genTest(string a) { return "unittest { i += " ~ a ~ "; }"; } void main() { // All unittests have been when we reach here. assert(i == 0 + 666 + 777); // Since 2.079 this passes! // assert(i == 0 + 666 + 666); } ``` fails with: dmd -unittest -run testcase.d since 2.079. It's caused by the naming of the unittest functions. The source location of the unittest is used in the name, but the source location inside mixins behaves strange: inside the mixin the linenumbers are offset with the line number of the mixin statement, but the column of the mixin statement is not reflected in Locs inside a mixin (only in the filename of the Loc). Thus only one function is made "...__unittest_L1_C1FZv" and it is called twice. (the second unittest gets the same name and is subsequently not codegenned because the symbol is already defined) --
May 19 2018