www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - __traits(getMember) works only the second time

reply "andre" <andre s-e-a-p.de> writes:
Hi,

by executing the example source code,
following output is returned:

Reference: Child
false
true

At first "childStr" is not found, then it is found?
Is this a bug?

Kind regards
André

-----------------

module app;

import test;

class Child : Parent
{
   mixin ComponentTemplate;
    property string childStr(){return "";}
}

void main()
{
   auto child = new Child();
   child.getParameters();
}

-----------------

module test;

template Params(this MyType)
{
   string[] Params()
   {
     pragma(msg, "Reference: " ~ MyType.stringof);
     pragma(msg, is(typeof(__traits(getMember, MyType, 
"childStr"))));
     pragma(msg, is(typeof(__traits(getMember, MyType, 
"childStr"))));
     return [];
   }
}

mixin template ComponentTemplate()
{
   private enum parameters = Params!(typeof(this));
	
   string[] getParameters()
   {
     return parameters;
   }
}

class Parent
{
    property string parentStr(){return "";}
}
Oct 10 2014
next sibling parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 10/10/2014 8:08 p.m., andre wrote:
 Hi,

 by executing the example source code,
 following output is returned:

 Reference: Child
 false
 true

 At first "childStr" is not found, then it is found?
 Is this a bug?

 Kind regards
 André

 -----------------

 module app;

 import test;

 class Child : Parent
 {
    mixin ComponentTemplate;
     property string childStr(){return "";}
 }

 void main()
 {
    auto child = new Child();
    child.getParameters();
 }

 -----------------

 module test;

 template Params(this MyType)
 {
    string[] Params()
    {
      pragma(msg, "Reference: " ~ MyType.stringof);
      pragma(msg, is(typeof(__traits(getMember, MyType, "childStr"))));
      pragma(msg, is(typeof(__traits(getMember, MyType, "childStr"))));
      return [];
    }
 }

 mixin template ComponentTemplate()
 {
    private enum parameters = Params!(typeof(this));

    string[] getParameters()
    {
      return parameters;
    }
 }

 class Parent
 {
     property string parentStr(){return "";}
 }
Wrong trait for the job. Use hasMember instead. Although interesting use case. Could be a bug somewhere in there.
Oct 10 2014
parent "andre" <andre s-e-a-p.de> writes:
I use the syntax "is(typeof(__traits(getMember, MyType, 
"childStr")))" to check whether a member is public visible or 
not. (The example above is only a reduced example)

By the way hasMember works correctly.
I will file an issue.

Kind regards
André

On Friday, 10 October 2014 at 07:25:28 UTC, Rikki Cattermole 
wrote:
 On 10/10/2014 8:08 p.m., andre wrote:
 Wrong trait for the job. Use hasMember instead.
 Although interesting use case. Could be a bug somewhere in 
 there.
Oct 10 2014
prev sibling parent "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
Certainly a bug; please file a report at https://issues.dlang.org/
Oct 10 2014