D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2856 - static opIndex does not compile for a templated struct/class
Summary: static opIndex does not compile for a templated struct/class
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2009-04-18 23:43 UTC by Rob Jacques
Modified: 2015-06-09 01:18 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rob Jacques 2009-04-18 23:43:28 UTC
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])