Bug 10597 – opDollar not callable in static constext

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-10T08:49:00Z
Last change time
2013-07-11T17:04:48Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-07-10T08:49:46Z
Discussed here: http://forum.dlang.org/thread/[email protected] //---- struct R { void opIndex(int); int opDollar(); } R r; void foo() { static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //ok } static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //fails (!) struct S { void foo() { static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //ok } static assert(is(typeof(r[0]))); //ok static assert(is(typeof(r[$]))); //fails (!) } //---- Calling opDollar in a "static context" fails. Apparently, it would appear that opDollar is looking for some sort of "this" or context pointer. If opDollar is defined as static, or enum, then the above code works. The error message is kind of weird too: main.d(15): Error: static assert (is(typeof(r.opIndex((int __dollar = r.opDollar(); , __dollar))))) is false
Comment #1 by k.hara.pg — 2013-07-10T19:46:29Z
Comment #2 by github-bugzilla — 2013-07-11T15:32:47Z