www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9272] New: opDispatch conflicts with UFCS on template functions

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

           Summary: opDispatch conflicts with UFCS on template functions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dransic gmail.com



---
struct Foo {
    void opDispatch(string s)() {}
}

void bar(T)(Foo f) {}

unittest {
    Foo foo;
    bar!int(foo);  // OK
    foo.bar!int(); // Error: foo.opDispatch isn't a template
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 05 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9272


Nils <nilsbossung googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |nilsbossung googlemail.com
         Resolution|                            |INVALID



---
No bug here, I think. opDispatch takes precedence and just fails to compile.

The same thing happens with
---
struct Foo {
    void bar() {}
}
---

The error message could be improved though. foo.opDispatch is a template. It's
foo.opDispatch!"bar" that is not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9272




---

 opDispatch takes precedence and just fails to compile.
Obviously. But is it really by design? This works, where opDispatch does not take precedence: --- struct Foo { void opDispatch(string s)() {} } void baz(Foo f) {} unittest { Foo foo; foo.baz(); // OK } --- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9272






 opDispatch takes precedence and just fails to compile.
Obviously. But is it really by design? This works, where opDispatch does not take precedence: --- struct Foo { void opDispatch(string s)() {} } void baz(Foo f) {} unittest { Foo foo; foo.baz(); // OK } ---
Just *template* opDispach is required for operator overloading. Therefore non-template function is simply ignored. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9272




---



 opDispatch takes precedence and just fails to compile.
Obviously. But is it really by design? This works, where opDispatch does not take precedence: --- struct Foo { void opDispatch(string s)() {} } void baz(Foo f) {} unittest { Foo foo; foo.baz(); // OK } ---
Just *template* opDispach is required for operator overloading. Therefore non-template function is simply ignored.
Yes. I understand why it doen't work at the moment. I just found it inconsistent. Maybe this should be an enhancement request then... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9272


Simen Kjaeraas <simen.kjaras gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras gmail.com



PST ---

 This works, where opDispatch does not take precedence:
 ---
 struct Foo {
     void opDispatch(string s)() {}
 }
 
 void baz(Foo f) {}
 
 unittest {
     Foo foo;
     foo.baz();     // OK
 }
Except, of course, opDispatch *does* take precedence here. Try this instead: import std.stdio : writeln; struct Foo { void opDispatch(string s)() { writeln("opDispatch: ", s); } } void baz(Foo f) { writeln("function: baz"); } void main( ) { Foo foo; foo.baz(); // OK } I can assure you it prints opDispatch: baz. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 05 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9272




---


 This works, where opDispatch does not take precedence:
 ---
 struct Foo {
     void opDispatch(string s)() {}
 }
 
 void baz(Foo f) {}
 
 unittest {
     Foo foo;
     foo.baz();     // OK
 }
Except, of course, opDispatch *does* take precedence here. Try this instead: import std.stdio : writeln; struct Foo { void opDispatch(string s)() { writeln("opDispatch: ", s); } } void baz(Foo f) { writeln("function: baz"); } void main( ) { Foo foo; foo.baz(); // OK } I can assure you it prints opDispatch: baz.
Ah! I was trapped by the minimalism of my example. OK thanks. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 06 2013