Bug 10990 – Passing in a module as a mixin to __traits(getUnitTests) behaves differently than passing in the module directly.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-07T19:49:00Z
Last change time
2013-09-12T15:56:20Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
opantm2+dbugs

Comments

Comment #0 by opantm2+dbugs — 2013-09-07T19:49:06Z
I don't know if this is specific to __traits(getUnitTests), though I doubt it is. When passing in a module directly, such as through __traits(getUnitTests, ptest2), a compiler error is raised saying that a module/aggregate is expected instead of an import. Passing the module in as a mixin, through __traits(getUnitTests, mixin("ptest2")) however works as expected. I tried with __traits(allMembers) and __traits(derivedMembers) which both seem to work fine, but I don't know of any other traits I could test with modules. Sample code passing in as module: import std.stdio; import ptest2; void main() { writeln(__traits(getUnitTests, ptest2).length); } Results in the following errors: ptest.d(6): Error: argument ptest2 to __traits(getUnitTests) must be a module or aggregate, not a import ptest.d(6): Error: no property 'length' for type 'bool' Passing in as mixin results in no errors and works as expected: import std.stdio; import ptest2; void main() { writeln(__traits(getUnitTests, mixin("ptest2")).length); } Code for ptest2.d: module ptest2; import std.stdio; unittest { writeln("First unittest."); }
Comment #1 by andrej.mitrovich — 2013-09-07T20:14:01Z
Comment #2 by github-bugzilla — 2013-09-12T15:56:04Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/49dd6b6cd0c10f2ef21d6d3da02dacd4d535de9e Fixes Issue 10990 - getUnitTest trait does not work with module import. https://github.com/D-Programming-Language/dmd/commit/e5bd2934c5b08fb197221bab82b3fac18bd99cf2 Merge pull request #2534 from AndrejMitrovic/Fix10990_2 Issue 10990 - getUnitTest trait does not work with a module import.