Bug 15874 – getSymbolsByUDA fails if struct has no UDAs

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-04-04T19:16:00Z
Last change time
2016-04-06T23:21:47Z
Assigned to
nobody
Creator
uldis.kalninsh

Comments

Comment #0 by uldis.kalninsh — 2016-04-04T19:16:02Z
I think, this specific case should work, but it does not. struct Test { int x; } struct UDA { } unittest { import std.traits; static assert(getSymbolsByUDA!(Test,UDA).length == 0); } This fails with: /usr/include/dlang/dmd/std/traits.d(6721): Error: array index [0] is outside array bounds [0 .. 0] /usr/include/dlang/dmd/std/traits.d(6726): Error: template instance std.traits.getSymbolsByUDA!(Test, UDA).toSymbols!() error instantiating The issue is that toSymbols within getSymbolsByUDA does not handles case with 0 matches. I think simple change to something like this should work: template toSymbols(names...) { static if (names.length == 0) toSymbols = AliasSeq!(); else mixin("alias toSymbols = AliasSeq!(symbol.%s, toSymbols!(names[1..$]));" .format(names[0])); }
Comment #1 by uldis.kalninsh — 2016-04-06T16:16:29Z
Created pull request: https://github.com/D-Programming-Language/phobos/pull/4164 This is first time I'm contributing to github and D, if I'm doing something wrong, please tell me :)
Comment #2 by github-bugzilla — 2016-04-06T23:21:46Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/cf4f09f12edbf3339c2e8d69e6b4d0e7fd2d660c Merge pull request #4164 from Ukalnins/issue_15874 Fix Issue 15874 - getSymbolsByUDA fails if struct has no UDAs