Bug 16364 – getUDAs and hasUDA do not give consistent results

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-08-08T09:35:00Z
Last change time
2016-10-01T11:46:29Z
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2016-08-08T09:35:19Z
Take this code import std.traits; void main() { struct AttrT(T) { string name; T value; } @AttrT!int("Answer", 42) int a; static assert(getUDAs!(a, AttrT).length == 1); static assert(getUDAs!(a, AttrT!int).length == 1); //static assert(hasUDA!(a, AttrT)); static assert(hasUDA!(a, AttrT!int)); @("alpha") int b; //static assert(getUDAs!(b, "alpha").length == 1); static assert(hasUDA!(b, "alpha")); } If either of the commented lines are uncommented, you get a compiler error. getUDAs is able to handle checking for UDAs which are templates without checking for a specific instantiation, whereas hasUDA is not, and hasUDA is able to check for UDAs that are values, wherea getUDAs cannot. It seems to me that the thing to do would be to make getUDAs handle all of the cases appropriately and then just make hasUDA use getUDAs. It would mean less code duplication and ensure that they the behave the same.
Comment #1 by github-bugzilla — 2016-08-10T20:15:39Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/29470ebb3c3c1475950e317fa033199d92b48cee Fix issue# 16364. Make getUDAs and hasUDA consistent. https://github.com/dlang/phobos/commit/af39effdb467af75c04ccf139a730a6d68c2f9a7 Merge pull request #4721 from jmdavis/issue_16364 Fix issue# 16364. Make getUDAs and hasUDA consistent.
Comment #2 by github-bugzilla — 2016-10-01T11:46:29Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/29470ebb3c3c1475950e317fa033199d92b48cee Fix issue# 16364. Make getUDAs and hasUDA consistent. https://github.com/dlang/phobos/commit/af39effdb467af75c04ccf139a730a6d68c2f9a7 Merge pull request #4721 from jmdavis/issue_16364