[Issue 2856] New: static opIndex does not compile for a templated struct/class

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 18 21:43:21 PDT 2009


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

           Summary: static opIndex does not compile for a templated
                    struct/class
           Product: D
           Version: 2.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: sandford at jhu.edu


Static opIndex functions result in compile time errors for templated structs
and classes. Using a typedef, fixes the issue. static opCall and generic static
functions don't appear to be affected.
Test case:
import std.stdio;

struct foo    { static void opIndex(int i) { writefln("foo"); } }
struct bar(T) { static void opIndex(int i) { writefln("bar"); } }

int main(char[][] args) {

    foo[1];
    //bar!(float)[1];      // Error (# = __LINE__)
    typedef bar!(float) B; 
    B[1];                  // Okay

    return 0;
}
main.d:#: Error: struct bar must be an array or pointer type, not void
main.d:#: Error: [i] has no effect in expression (struct bar[1])


-- 



More information about the Digitalmars-d-bugs mailing list