[Issue 5046] New: Wrong type of implicit 'this' in struct/class templates

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 12 15:28:42 PDT 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 at puremagic.com
        ReportedBy: rsinfu at gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu at 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: -------


More information about the Digitalmars-d-bugs mailing list