http://d.puremagic.com/issues/show_bug.cgi?id=4413

           Summary: typeof(this) doesn't work in method template signature
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2010-07-01 14:27:43 PDT ---
dmd v2.047 shows a compilation error on the call to bar4, but in my opinion the
compiler has to compile all four those bar methods:


struct Foo {
    alias typeof(this) typeof_this;
    void bar1(typeof_this other) {}
    void bar2()(typeof_this other) {}
    void bar3(typeof(this) other) {}
    void bar4()(typeof(this) other) {}
}
void main() {
    Foo f;
    f.bar1(f); // OK
    f.bar2(f); // OK
    f.bar3(f); // OK
    f.bar4(f); // ERR
}


The generated errors:
test.d(13): Error: template test.Foo.bar4() does not match any function
template declaration
test.d(13): Error: template test.Foo.bar4() cannot deduce template function
from argument types !()(Foo)


The problem of bar4 has shown up in D2 code similar to this one, where I have
used typeof(this) to follow the DRY strategy and avoid repeating the struct
name more than one time:

struct Vec2 {
    float x, y;
    auto opBinary(string op)(typeof(this) other) if (op == "+") {
      ...
    }
}


A workaround that can be used is:

struct Vec2 {
    float x, y;
    alias typeof(this) typeof_this;
    auto opBinary(string op)(typeof_this other) if (op == "+") {
      ...
    }
}

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

Reply via email to