Thread overview
[Issue 5046] New: Wrong type of implicit 'this' in struct/class templates
Oct 12, 2010
Shin Fujishiro
Jul 14, 2011
Kenji Hara
Jul 19, 2011
Walter Bright
October 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5046

           Summary: Wrong type of implicit 'this' in struct/class
                    templates
           Product: D
           Version: D2
          Platform: x86
        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-10-12 15:28:10 PDT ---
Implicit 'this' references in struct/class templates are wrongly typed under certain circumstance and the following code doesn't compile.
--------------------
void main()
{
    auto va = S!("", int)();
    auto vb = makeS!("", int)();
}

struct S(alias p, T)
{
    T s;
    T fun() { return s; }   // (10)
}

S!(p, T) makeS(alias p, T)()
{
    return typeof(return)();
}
--------------------
% dmd -o- -c test.d
test.d(10): Error: this for s needs to be type S not type S!("",int)
--------------------

The error does not happen if

- Either va or vb is commented out,
- Template parameter "alias p" is replaced with "string p", or
- "return s" at line (10) is replaced with "return this.s".

The Sequence struct in std.range hits this problem. It currently works around the problem by supplying explicit 'this' to all fields.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5046


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |k.hara.pg@gmail.com


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-07-14 04:22:25 PDT ---
https://github.com/D-Programming-Language/dmd/pull/94

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5046


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-07-18 20:17:45 PDT ---
https://github.com/D-Programming-Language/dmd/commit/d3c324c8b1290c84e4808f9ac040e70a3e27b7f6

https://github.com/D-Programming-Language/dmd/commit/ca51706314e24b1b65a0417fb6529074ef988727

https://github.com/D-Programming-Language/dmd/commit/6052888a19f0dc048c2aae07d03d5b239b0901ff

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