Bug 2856 – static opIndex does not compile for a templated struct/class

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-04-18T23:43:00Z
Last change time
2015-06-09T01:18:03Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
sandford

Comments

Comment #0 by sandford — 2009-04-18T23:43:28Z
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])
Comment #1 by k.hara.pg — 2011-10-15T04:07:40Z
Comment #2 by bugzilla — 2011-11-16T00:26:48Z