DMD fail when using both reflection and UDA

bioinfornatics via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 1 09:07:47 PDT 2014


On Sunday, 1 June 2014 at 16:02:47 UTC, bioinfornatics wrote:
> DMD (dmdfe 2.066) fail when i use UDA which store a delegate
>
>
> code below works if i remove @section UDA otheswise it give this
> error:
>
> dmd: statement.c:714: ErrorStatement::ErrorStatement(): 
> Assertion
> `global.gaggedErrors || global.errors' failed.
>
>
> is a bug  ?
>
>
>
> ------- CODE also on dpaste http://dpaste.dzfl.pl/3a3d660bd3bc
> --------
> import std.stdio;
> import std.typecons : Tuple;
> import std.typetuple : Filter;
>
>
> struct attribute{}
>
> @attribute
> struct section( alias start, alias end)
> {
>      alias checkStart = start;
>      alias checkEnd = end;
> }
>
> template hasSection(T)
> {
>      static bool helper()
>      {
>          foreach(memberName; __traits(allMembers, T))
>          {
>              foreach(attr; __traits(getAttributes,
> __traits(getMember, T, memberName)))
>              {
>                  static if(is(attr == Section))
>                      return true;
>              }
>          }
>          return false;
>      }
>
>      enum hasSection = helper();
> }
>
> struct Data{
>      @section!( ( words ) =>  words[0] == '@'                 , 
> (
> words ) =>  words[0] == '\n' )
>      string a;
>      @section!( ( words ) =>  words[0] > 63 && words[0] <115  , 
> (
> words ) =>  words[0] == '\n' )
>      string b;
>      @section!( ( words ) =>  words[0] == '+'                 , 
> (
> words ) =>  words[0] == '\n' )
>      string c;
> }
>
> template toTuple(T){
>      static string maker(){
>          string statement = "alias toTuple = Tuple!(";
>          foreach(const memberName; __traits(allMembers, T)){
>              //~ mixin(`alias f = Filter!(hasSection,
> __traits(getAttributes, T.` ~ memberName ~ `));`);
>              statement ~=  typeof(__traits(getMember, T,
> memberName)).stringof  ~ ",\"" ~ memberName ~ "\", " ;
>          }
>          statement = statement[0..$-2] ~ ") ;" ; // $-2 to 
> remove
> extra comma
>          return statement;
>      }
>      mixin( maker() );
> }
>
>
> void main()
> {
>      alias A = toTuple!Data;
>      A a;
>      a[0] = 1;
>      a.x = 1;
> }


ok it seem problem from my code a type string i need to
understand why


More information about the Digitalmars-d-learn mailing list