Bug 7702 – opDispatch goes into infinite loop

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-13T06:29:00Z
Last change time
2012-03-15T15:41:01Z
Keywords
ice, pull
Assigned to
nobody
Creator
michal.minich
See also
http://d.puremagic.com/issues/show_bug.cgi?id=5733

Comments

Comment #0 by michal.minich — 2012-03-13T06:29:49Z
struct S { template opDispatch (string name) { void opCall (T) () @property {} } } struct S3 { auto opCall (T) () @property { struct S4 { void opDispatch (string name) () @property {} } S4 s4; return s4; } } void main () { S s; s.opDispatch!"x".opCall!int; // OK s.x.opCall!int; // OK s.opDispatch!("x")!(int); // parse error s.x!int; // infinite loop in dmd S3 s3; s3.opCall!int.opDispatch!("x"); // OK s3.opCall!int.x; // OK s3!int.x; // Error: template instance s3!(int) s3 is not a template declaration, it is a variable }
Comment #1 by k.hara.pg — 2012-03-13T07:30:50Z
The infinite loop in dmd is the real issue. struct S { template opDispatch (string name) { //void opCall (T) () @property {} // not need } } void main () { S s; s.x!int; // infinite loop in dmd } And others are not errors, because their error messages are valid. Then I replace the subject. ---- opCall works only for call syntax, e.g. rewriting foo(args) to foo.opCall(args). If you want to implement s.x!int with opDispatch, *nested opDispatch idiom* like follows would work. struct S { template opDispatch(string name) { T opDispatch(T)() @property { return T.init; } } } void main() { S s; assert(s.x!int == 0); // same as s.opDispatch!("x").opDispatch!(int)() }
Comment #2 by k.hara.pg — 2012-03-13T18:36:04Z
Comment #3 by github-bugzilla — 2012-03-15T15:05:24Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/380b2f8a26da0cb5c6a263608efb2c7020f25c7e Merge pull request #808 from 9rnsr/fix7702 Issue 7702 & 5733 - opDispatch goes into infinite loop