www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4617] New: Alias this'ed symbols cannot be passed to templates

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

           Summary: Alias this'ed symbols cannot be passed to templates
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu gmail.com> 2010-08-10 22:38:03 PDT
---
DMD tries to evaluate alias this'ed symbols.  It causes a compile error on
instantiating templates with alias this'ed symbols.

-------------------- test1.d
alias Test!(S.square) test;

struct S
{
    struct F
    {
        int  square(int  n) { return n*n; }
        real square(real n) { return n*n; }
    }
    F forward;

    alias forward this;
}

template Test(alias k) {}
--------------------
% dmd -o- -c test1.d
test1.d(1): Error: function test1.S.F.square (int n) is not callable using
argument types ()
test1.d(1): Error: expected 1 function arguments, not 0
% _
--------------------

TemplateInstance::semanticTiargs() (or TypeQualified::resolveHelper()) resolves
forwarded symbols as dotvar expressions and tries to evaluate them at compile
time.  Apparently, it causes the problem.

The error does not occur if the symbol is forwarded directly:
-------------------- test2.d
alias Test!(S.square) test;

struct S
{
    struct F
    {
        int  square(int  n) { return n*n; }
        real square(real n) { return n*n; }
    }
    F forward;

    alias forward.square square;    // okay
}

template Test(alias k) {}
--------------------
% dmd -o- -c test2.d
% _
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4617



--- Comment #1 from Shin Fujishiro <rsinfu gmail.com> 2010-08-10 22:39:48 PDT
---
The bug also causes a false negative of __traits(isSame), becuase isSame reuses
the same algorithm as template instantiation:
-------------------- test3.d
static assert( __traits(isSame, S.square, S.forward.square) );

struct S
{
    struct F
    {
        int  square(int  n) { return n*n; }
        real square(real n) { return n*n; }
    }
    F forward;

    alias forward this;
}
--------------------
% dmd -o- -c test3.d
test3.d(1): Error: static assert  (__traits(isSame,forward.square,square)) is
false
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4617


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
            Version|unspecified                 |D2


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2012-06-30 05:07:55 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1032

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


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 04 2013