www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9091] New: Perhaps another forward referencing bug.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091

           Summary: Perhaps another forward referencing bug.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: turkeyman gmail.com



I've created a new bug from this thread:
http://d.puremagic.com/issues/show_bug.cgi?id=9065
That thread has forked into unrelated conversations, and I suspect this is a
separate bug anyway...

Kenji: I boiled this down as much as I could...




class Test
{
    void func()
    {
        void templateFunc( T )( ref const T obj )
        {
            foreach( m; __traits( allMembers, T ) )
            {
                pragma(msg, m);
                static if( isVariable!( __traits(getMember, T, m) ) )
                {
                    //...
                }
            }
        }

        templateFunc( this );
    }

    // some class members
    int x;
}

isVariable throws lots of errors when considering the class members.

Note:
  __traits(allMembers, T) and __traits(getMember, T, m)

These should also work with class instances, not just types, eg:
  __traits(allMembers, obj) and __traits(getMember, obj, m)

And these combinations should also work:
  __traits(allMembers, T) and __traits(getMember, obj, m)
  __traits(allMembers, obj) and __traits(getMember, T, m)

All these configurations throw errors, and the errors are different for each
configuration.


Depends on:

/**
 * Detect whether symbol or type $(D X) is a function.
 */
template isFunction(X...) if (X.length == 1)
{
    static if (is(typeof(&X[0]) U : U*) && is(U == function) ||
               is(typeof(&X[0]) U == delegate))
    {
        // x is a (nested) function symbol.
        enum isFunction = true;
    }
    else static if (is(X[0] T))
    {
        // x is a type.  Take the type of it and examine.
        enum isFunction = is(T == function);
    }
    else
        enum isFunction = false;
}

/**
 * Detect whether symbol $(D X) is a run-time variable.
 */
template isVariable(X...) if (X.length == 1)
{
    static if (!is(X[0]) &&
               !is(typeof(X[0]) == void) &&
               !isFunction!(X[0]))
    {
        enum isVariable =
            is(typeof({ auto ptr = &X[0]; }))
         || is(typeof({ enum off = X[0].offsetof; }));
    }
    else
        enum isVariable = false;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 28 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091


Manu <turkeyman gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major



I have a hard deadline (like, proper hard) tomorrow, I'd really like to have
this fix in there. Is there anyone who can possibly look into/comment on it?

I bumped the priority to help it get noticed...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091




Furthermore reduced case:

template isVariable(X...) if (X.length == 1)
{ enum isVariable = true; }

class C
{
    int x;
    void func()
    {
        enum is_x = isVariable!(__traits(getMember, C, "x"));
    }
}

I posted a report bug 9100 to explain the current semantic analysis weird
behavior on template argument. I think that it is the root cause of this bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Perhaps another forward     |Using __traits(getMember)
                   |referencing bug.            |on template argument fails
                   |                            |inside member function



Changed summary.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid



https://github.com/D-Programming-Language/dmd/pull/1340

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a4fb02fb3572c1616e7aad55fdd07b22b12242b8
fix Issue 9091 - Using __traits(getMember) on template argument fails inside
member function

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



Fixed?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091





 Fixed?
Kenji was working on these, the prototypes he gave me worked for me, I'm not sure if it was accepted/merged though. Kenji? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091




Unfortunately, this still not be fixed completely.

https://github.com/D-Programming-Language/dmd/pull/1406

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 17 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/8a781342c90c0fc93a52876ceb972500a1603d42
fix Issue 9091 - Using __traits(getMember) on template argument fails inside
member function

Use ThisExp instead of VarExp to avoid interpretation on template arguments.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 01 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9091


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 01 2013