Bug 17426 – "version(none):" cant be overwritten by its counterpart
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-05-24T05:43:00Z
Last change time
2017-05-24T12:54:00Z
Keywords
wrong-code
Assigned to
nobody
Creator
b2.temp
Comments
Comment #0 by b2.temp — 2017-05-24T05:43:44Z
this test cast should crash at run-time
dmd veroverwrite.d -main -unittest
veroverwrite.d:
---
version(none):
unittest {assert(false);}
version(all):
unittest {assert(false);} // not compiled
version(none):
unittest {assert(false);}
---
Comment #1 by dlang-bugzilla — 2017-05-24T12:54:00Z
The rule being followed here is:
{
version(x):
...code...
}
is equivalent to
{
version(x)
{...code...}
}
i.e. everything is wrapped until the end of the current scope, or file if at the top level.
Thus, your code is equivalent to:
version(none)
{
unittest {assert(false);}
version(all)
{
unittest {assert(false);} // not compiled
version(none)
{
unittest {assert(false);}
}
}
}
Making your code work as intuitively expected would mean breaking consistency with the rule (though adding a warning for this to either DMD or DScanner might not be a bad idea).