www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - filter custom version id from __traits code

reply Basile B. <b2.temp gmx.com> writes:
I don't see how to filter a custom version identifier from this 
traits code:

---
module test;

import std.traits   : isCallable;
version(all) version = my_version;

private bool onlyFuncs()
{
     bool result = true;
     foreach (member; __traits(allMembers, mixin(__MODULE__)))
     {
         static if (!is(mixin(member) == module) && 
!(is(mixin(member))))
         static if (__traits(getOverloads, mixin(__MODULE__), 
member, true).length == 0)
         {
             pragma(msg, "`", member, "` ", "is not a type or a 
function");
             result = false;
             break;
         }
     }
     return result;
}
static assert(onlyFuncs(), "this script must hide globals as 
local static variable in a getter");

void main(){}
---

 : Error: undefined identifier my_version in module test
 onlineapp.d(12): Error: module test.my_version cannot be 
 resolved
 onlineapp.d(21):        called from here: onlyFuncs()
 onlineapp.d(21):        while evaluating: static
Any idea ?
Jun 09 2020
parent reply Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Tuesday, 9 June 2020 at 17:40:10 UTC, Basile B. wrote:

 Any idea ?
As I replied in the issue report:
 Instead of
 
 static if (!is(mixin(member) == module) && !(is(mixin(member))))
 
 use
 
 static if (is(typeof(mixin(member))))
Jun 09 2020
parent Basile B. <b2.temp gmx.com> writes:
On Tuesday, 9 June 2020 at 18:08:01 UTC, Stanislav Blinov wrote:
 On Tuesday, 9 June 2020 at 17:40:10 UTC, Basile B. wrote:

 Any idea ?
As I replied in the issue report:
 Instead of
 
 static if (!is(mixin(member) == module) && 
 !(is(mixin(member))))
 
 use
 
 static if (is(typeof(mixin(member))))
Yes thanks again for the help.
Jun 09 2020