Jump to page: 1 2
Thread overview
[Issue 9091] New: Perhaps another forward referencing bug.
Nov 28, 2012
Manu
Nov 29, 2012
Manu
Dec 01, 2012
Kenji Hara
[Issue 9091] Using __traits(getMember) on template argument fails inside member function
Dec 01, 2012
Kenji Hara
Dec 01, 2012
Kenji Hara
Jan 13, 2013
yebblies
Jan 13, 2013
Manu
Jan 18, 2013
Kenji Hara
Mar 01, 2013
Kenji Hara
November 28, 2012
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


--- Comment #0 from Manu <turkeyman@gmail.com> 2012-11-28 04:08:31 PST ---
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: -------
November 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9091


Manu <turkeyman@gmail.com> changed:

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


--- Comment #1 from Manu <turkeyman@gmail.com> 2012-11-29 04:20:58 PST ---
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: -------
December 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9091



--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-11-30 20:04:31 PST ---
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: -------
December 01, 2012
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


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2012-11-30 20:08:21 PST ---
Changed summary.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 01, 2012
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


--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2012-11-30 21:17:32 PST ---
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: -------
December 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9091



--- Comment #5 from github-bugzilla@puremagic.com 2012-12-09 12:52:00 PST ---
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: -------
January 13, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9091


yebblies <yebblies@gmail.com> changed:

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


--- Comment #6 from yebblies <yebblies@gmail.com> 2013-01-13 17:31:27 EST ---
Fixed?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 13, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9091



--- Comment #7 from Manu <turkeyman@gmail.com> 2013-01-13 00:54:56 PST ---
(In reply to comment #6)
> 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: -------
January 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9091



--- Comment #8 from Kenji Hara <k.hara.pg@gmail.com> 2013-01-17 20:14:14 PST ---
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: -------
March 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9091



--- Comment #9 from github-bugzilla@puremagic.com 2013-03-01 01:32:04 PST ---
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: -------
« First   ‹ Prev
1 2